Search code examples
.netfile-ioasynchronousfilestream

Is Asynchronous file IO thread safe?


Is asynchronous file IO like FileStream.BeginWrite thread safe? If not, then it need to wrap with "SyncLock", that's mean it is still blocking thread.


Solution

  • FileStream.BeginWrite already starts a new thread to access the files. You don't need to start the FileStream.BeginWrite on a separate thread (because that will be thread in a thread). On the other hand, multiple FileStream.BeginWrite functions should not be accessing the same file at the same time.