Isolated Storage and Multithreading

The documentation is a little weak on thread safety when it comes to Isolated Storage, with just a little message on the subject: “Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.”.

What I’ve found is this: Reading files from Isolated Storage is fine from multiple threads at the same time – obviously if a thread is saving the file then things are a little murkier.

However, writing files is not thread safe. Do not attempt to write two different files at the same time to Isolated Storage, you’ll get an exception sooner or later.

My fix is a little messy, I have a global lock object I use whenever I want to write to Isolated Storage; this means I can only ever save one file at a time.

Leave a Reply