views:

486

answers:

1

I'm using IStorage's Compound File Implementation from C# (StgCreateDocfile).

Is it safe to access one IStorage / IStream instance from multiple threads, provided I synchronized the reads and writes myself? Or are there any COM issues that might be problematic here?

For example, can I safely call EnumElements to get all streams in the storage, while at the same time (and from a different thread) creating and writing a new stream?

I have already written a stress test for my implementation, and it showed no problems, but I need to be 100% sure. I haven't found this information in the MSDN docs.

+1  A: 

Tuff one. There's a snippet about it in the documentation for the ILockBytes interface. It says that the default implementations of IStorage and IStream implement IMarshal. Which would make them thread-safe, provided you follow COM threading rules. That's easy to forget when the interface pointers are in-proc. You'd have to use something like CoMarshalInterThreadInterfaceInStream() or IGlobalInterfaceTable. You'll get away with not marshaling by locking yourself.

Hans Passant