Onbeheerde uitzondering: System.AggregateException: Er zijn één of meer fouten opgetreden. ---> System.IO.IOException: Bestand "C:\SyncTemp\Position\Taxi\2017\09\09\Time\0000.dat" wordt door een ander proces gebruikt, dus dit bestand is niet toegankelijk. op System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) In System.IO.FileStream.Init(Stringpad, FileMode-modus, FileAccess-toegang, Int32-rechten, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions-opties, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) In System.IO.FileStream: ctor(Stringpad, FileMode-modus, FileAccess-toegang, FileShare delen) In System.IO.File.Open(Stringpad, FileMode-modus, FileAccess-toegang) Bij ConsoleApp1.FileReadHelper.SingleFile(String path) locatie C:\project\my\TestNet\ConsoleApp1\FileReadHelper.cs: regelnummer 27 In ConsoleApp1.FileReadHelper.<>c__DisplayClass3_0. <MultipleFilesAsync>b__0(String x) Positie C:\project\my\TestNet\ConsoleApp1\FileReadHelper.cs: Regel nummer 68 In System.Threading.Tasks.Parallel.<>c__DisplayClass17_0'1. <ForWorker>b__1() In System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask) In System.Threading.Tasks.Task.<>c__DisplayClass176_0. <ExecuteSelfReplicating>b__0(Object) --- Einde van de interne uitzonderingstack trace --- In System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) In System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, AnnuleringToken annuleringstoken) In System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action'1 body, Action'2 bodyWithState, Func'4 bodyWithLocal, Func'1 localInit, Actie'1 localFinally) In 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 localEindeind) bij System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable'1 source, Action'1 body) In ConsoleApp1.FileReadHelper.MultipleFilesAsync(IEnumerable'1 pad) op locatie C:\project\my\TestNet\ConsoleApp1\FileReadHelper.cs: regelnummer 66 Bij ConsoleApp1.Program.Main(String[] args) positie C:\project\my\TestNet\ConsoleApp1\Program.cs: regelnummer 73 Druk alstublieft op een willekeurige toets om door te gaan...
De fout is duidelijk, dat wil zeggen, het bestand kan niet worden benaderd, het bestand kan niet worden gelezen, wat een uitzondering is die onder multithreading wordt gegooid
Ik las hoe het document is geschreven:
Ik heb alleen de leesmodus ingesteld, niet de schrijfmodus, en ontdekte dat er onder multithreading nog steeds een foutmelding zal zijn, is het niet alleen-lezen?
Als het alleen-lezen is, zou het geen fout moeten zijn
Oplossing:
Dit zou bestanden in alleen-lezen-modus moeten zijn, het getest en vastgesteld dat het geen fout is, en hetzelfde bestand kan tegelijkertijd onder meerdere threads worden gelezen
|