Yönetilmeyen istisna: System.AggregateException: Bir veya daha fazla hata meydana geldi. ---> System.IO.IOException: "C:\SyncTemp\Position\Taxi\2017\09\09\Time\0000.dat" dosyası başka bir süreç tarafından kullanılıyor, bu nedenle bu dosyaya erişilemiyor. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) System.IO.FileStream.Init(String path, FileMode mode, FileAccess erişimi, Int32 hakları, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) System.IO.FileStream içinde: ctor(String yolu, FileMode modu, FileAccess erişimi, FileShare paylaşımı) System.IO.File.Open'da (String yolu, FileMode modu, FileAccess erişimi) ConsoleApp1.FileReadHelper.SingleFile(String path) konumunda C:\project\my\TestNet\ConsoleApp1\FileReadHelper.cs: satır numarası 27 ConsoleApp1.FileReadHelper.<>c__DisplayClass3_0 içinde. <MultipleFilesAsync>b__0(Dizi x) Pozisyon C:\project\my\TestNet\ConsoleApp1\FileReadHelper.cs: Satır numarası 68 System.Threading.Tasks.Parallel.<>c__DisplayClass17_0'1 içinde. <ForWorker>b__1() System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask) içinde In System.Threading.Tasks.Task.<>c__DisplayClass176_0. <ExecuteSelfReplicating>b__0(Nesne) --- İç istisna yığını izinin sonu --- System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) içinde System.Threading.Tasks.Task.Wait(Int32 milisecondsTimeout, CancellationToken cancellationToken) içinde System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action'1 body, Action'2 bodyWithState, Func'4) içinde bodyWithLocal, Func'1 localInit, Action'1 localson) System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable'1 source, ParallelOptions, Action'1 body, Action'2 bodyWithState, Action'3) içinde bodyWithStateAndIndex, Func'4 bodyWithStateAndLocal, Func'5 bodyWithEverything, Func'1 localInit, Action'1 local'Nihayet) at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable'1 kaynak, Action'1 gövdesi) ConsoleApp1.FileReadHelper.MultipleFilesAsync(IEnumerable'1 path) içinde C:\project\my\TestNet\ConsoleApp1\FileReadHelper.cs: 66. satır numarası ConsoleApp1.Program.Main(String[] args) konumunda C:\project\my\TestNet\ConsoleApp1\Program.cs: satır numarası 73 Lütfen devam etmek için herhangi bir tuşa basın. . . .
Hata açıktır, yani dosyaya erişilemiyor, dosya okunamıyor, bu da çoklu iş parçacığı altında atılan bir istisnadır
Belgenin nasıl yazıldığını okudum:
Sadece okuma modunu ayarladım, yazma modunu değil ve çoklu iş parçacıklığında yine bir hata olduğunu gördüm, sadece okunabilir değil mi?
Eğer sadece okunabilirse, hata olmamalı.
Çözüm:
Bu, dosyaları yalnızca okunma modunda okuma şeklinde olmalı, test ettim ve hata olmadığını, aynı dosyanın birden fazla iş parçacığı altında aynı anda okunabildiğini gördüm
|