Ubehandlet unntak: System.AggregerUnntak: En eller flere feil har oppstått. ---> System.IO.IOException: Filen "C:\SyncTemp\Position\Taxi\2017\09\09\Time\0000.dat" brukes av en annen prosess, så denne filen kan ikke nås. på System.IO.__Error.WinIOError(Int32 feilkode, streng maybeFullPath) I System.IO.FileStream.Init(Strengsti, FileMode-modus, FileAccess-tilgang, Int32-rettigheter, boolsk useRights, FileShare-deling, Int32 bufferSize, FileOptions-alternativer, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) I System.IO.FileStream: ctor(Strengsti, Filmodus-modus, Filtilgang, Fildelingsdeling) I System.IO.File.Open(Strengsti, FileMode-modus, FileAccess-tilgang) På ConsoleApp1.FileReadHelper.SingleFile(String path) lokasjon C:\project\my\TestNet\ConsoleApp1\FileReadHelper.cs: linjenummer 27 I ConsoleApp1.FileReadHelper.<>c__DisplayClass3_0. <MultipleFilesAsync>b__0(Streng x) Posisjon C:\project\my\TestNet\ConsoleApp1\FileReadHelper.cs: Linjenummer 68 I System.Threading.Tasks.Parallel.<>c__DisplayClass17_0'1. <ForWorker>b__1() I System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask) I System.Threading.Tasks.Task.<>c__DisplayClass176_0. <ExecuteSelfReplicating>b__0(Objekt) --- Slutt på den interne unntaksstakksporingen --- I System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) I System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) I System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action'1 body, Action'2 bodyWithState, Func'4 bodyWithLocal, Func'1 localInit, Action'1 localFinally) I System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable'1 source, ParallelOptions, Action'1 body, Action'2 bodyWithState, Action'3 bodyWithStateAndIndex, Func'4 bodyWithStateAndLocal, Func'5 bodyWithEverything, Func'1 localInit, Action'1 localTFinally) på System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable'1 kilde, Action'1 kropp) I ConsoleApp1.FileReadHelper.MultipleFilesAsync(IEnumerable'1 path) på sted C:\project\my\TestNet\ConsoleApp1\FileReadHelper.cs: linjenummer 66 På ConsoleApp1.Program.Main(String[] args) posisjon C:\project\my\TestNet\ConsoleApp1\Program.cs: linjenummer 73 Vennligst trykk på en hvilken som helst tast for å fortsette. . . .
Feilen er åpenbar, det vil si at filen ikke kan nås, filen kan ikke leses, noe som er et unntak under multitråding
Jeg leste hvordan dokumentet er skrevet:
Jeg satte bare lesemodus, ikke skrivemodus, og fant ut at under multitråding vil det fortsatt være en feil, er det ikke skrivebeskyttet?
Hvis det er skrivebeskyttet, skal det ikke være en feil
Løsning:
Dette skal lese filer i skrivebeskyttet modus, testet det, og fant ut at det ikke er en feil, og at samme fil kan leses samtidig under flere tråder
|