Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 906
kevin Avatar asked Sep 27 '26 01:09

kevin


2 Answers

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.

like image 121
Teoman Soygul Avatar answered Sep 28 '26 15:09

Teoman Soygul


Also if the resource is accessed by multiple threads, it means it is a shared resource and there are plentiful of resources about using them in c#.

like image 43
None Avatar answered Sep 28 '26 14:09

None



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!