-3

what happens when two thread are reading from the same file ?

i'm having an out of boundary exception on a dictionary that i'm filling using a file. multiple tests are being executed in the same time, each in a separate thread and each one of them is trying to recreate the Dictionary (i'm just testing here). does reading from the same file using multitasking generate such exception ?

  • 1
    [What have your tried?](http://idownvotedbecau.se/noattempt/) , http://idownvotedbecau.se/nodebugging/ . The best way to find out if something causes an exception, is to run it. We can guess all day if something that is not tested will throw an exception. However, there are probably dozens of ways to get passed/fix the exception. A quick search on your quesiton returned- https://stackoverflow.com/questions/3507770/write-to-a-file-from-multiple-threads-asynchronously-c-sharp . – Jaskier Jan 07 '19 at 15:26

1 Answers1

-1

You cannot read or write the same file at the same time from several threads. To avoid these exceptions you can use Semaphore or SemaphoreSlim

Stefan W.
  • 342
  • 1
  • 9