How can I create a system/multiprocess Mutex to co-ordinate multiple processes using the same unmanaged resource.
Background:
I’ve written a procedure that uses a File printer, which can only be used by one process at a time. If I wanted to use it on multiple programs running on the computer, I’d need a way to synchronize this across the system.
There is a constructor overload for checking for an existing mutex.
http://msdn.microsoft.com/en-us/library/bwe34f1k(v=vs.90).aspx
So…
If you fail to call
m.ReleaseMutex()it will be called ‘abandoned’ when your thread exits. When another thread constructs the mutex, the exceptionSystem.Threading.AbandonedMutexExceptionwill be thrown telling him it was found in the abandoned state.