Mutex across network - C#.NET

泪湿孤枕 提交于 2020-01-03 18:42:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!