Main Site Documentation

Is the .Net Micro File system thread safe?


Just want to double check that it is safe for one thread to write to one file on a microSD card while another thread reads from a different file on the same card.

I’ve been pretty successful at writing my current app so nothing blocks except for when I have to transfer a file using Iridium satellites. My code uses XModem for .Net Micro from Iggmoe and it would be pretty hard to make that non-blocking. So my current code blocks and my state machine stalls while I transfer the file. It makes sense to me to move the file transfer to another thread so my state machine can continue monitoring the system but I just want to make sure the two threads won’t be stomping on each other trying to access the file system. Also, I have to figure out how to pass the parameters the file transfer thread needs to access the SD card.

Thanks for the help.


I don’t see why it shouldn’t be thread safe.
But the number of open file handles is quite limited.
So far I did not experience any issues when using file streams from different threads.


@ Gene - Accessing different files from too concurrent threads is probably ok, but if you want to be dead sure, locks come into rescue:

private static object _theLock=new object(); //Make this one global so both threads can access it

void FunctionFromThread1(){
   lock (_theLock){
      //Do whatever you want here

void FunctionFromThread2(){
   lock (_theLock){
      //Do whatever you want here, too