我正在尝试编写一个多线程应用程序,并且需要使用Monitoer.Enter/Exit/Wait/Pulse
。我已经创建了一个Lock对象并在其自己的类中使用它,如下所示:
public partial class domain
/*I dont sure this is the good practice way to mange DDD Layers (if anybody have a comment about it)*/
{
Public class Peer2PeerCom
{
public static readonly object locker = new object();
//other stuff here
//...
//somwhere here
Monitor.Pulse(locker);
}
}
在另一个班级中,我想/需要像那样使用储物柜。
public class Control
{
public domain.Peer2PeerCom Dom_P2PCom = new domain.Peer2PeerCom();
internal void connection ( int port , string IpAdress)
{
Monitor.Enter(Dom_P2PCom.locker);
//do stuff here
Monitor.wait(Dom_P2PCom.locker);
//..
Monitor.Exit(Dom_P2PCom.locker);
}
}
但是当我尝试时,我无法识别locker
,我认为这是因为它是static
,但我不知道如何在不使整个类变为静态的情况下进行更正。
Peer2PeerCom.locker
? - Sayse