问题
I have a message queue on a shared system. This queue is accessed by 2 processes which run on 2 other machines. I need to control access to this queue by the 2 processes. So I need a "network mutex". How can I achieve this?
I don't think this is supported out of the box in C#.NET but if I have missed something very obvious, do point me in the right direction. This question has been asked before but the solutions suggested involved a database. I dont have any database in question.
How To Mutex Across a Network?
回答1:
You need a third process, which actually owns the queued items. The two workers each ask the third process for the next item, and it's this third process that polices access and acts as the lock.
回答2:
Use MSMQ or other queuing system design for use across a network.
Win32 has no cross machine synchronisation primitives like a muxtex, you might be able to build something from file locking, but you would just be re-inventing MSMQ.
回答3:
I think I found what I was looking for ... and it turns out to be a simple property setting!
http://msdn.microsoft.com/en-us/library/system.messaging.messagequeue.denysharedreceive%28VS.80%29.aspx
Should have explored this first!!
Jeff key has reported an issue with this and his experience: http://weblogs.asp.net/jkey/archive/2004/05/12/130922.aspx
Thank you all for the help.
来源:https://stackoverflow.com/questions/2176231/mutex-across-network-c-net