那怎么在A里写代码可以启动B呢?我试了一下以下代码,但还是无法启动服务B protected override void OnStart(string[] args) { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new ServiceB() }; ServiceBase.Run(ServicesToRun); }
// Create the named mutex. Only one system object named // "MyMutex" can exist; the local Mutex object represents // this system object, regardless of which process or thread // caused "MyMutex" to be created. Mutex m = new Mutex(false, "MyMutex"); // Try to gain control of the named mutex. If the mutex is // controlled by another thread, wait for it to be released. Console.WriteLine("Waiting for the Mutex."); m.WaitOne(); http://msdn.microsoft.com/zh-cn/library/f55ddskf%28v=vs.110%29.aspx
你这叫什么"依赖关系"啊
如果在B的代码里去判断A,此时其实B已经启动了,只不过不执行真正的处理逻辑而已或者你在A里写代码,A启动了就把B也启动,B设置成手动启动,而不是自动启动
http://msdn.microsoft.com/zh-cn/library/system.threading.mutex.aspx
那怎么在A里写代码可以启动B呢?我试了一下以下代码,但还是无法启动服务B
protected override void OnStart(string[] args)
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new ServiceB()
};
ServiceBase.Run(ServicesToRun); }
// "MyMutex" can exist; the local Mutex object represents
// this system object, regardless of which process or thread
// caused "MyMutex" to be created.
Mutex m = new Mutex(false, "MyMutex"); // Try to gain control of the named mutex. If the mutex is
// controlled by another thread, wait for it to be released.
Console.WriteLine("Waiting for the Mutex.");
m.WaitOne();
http://msdn.microsoft.com/zh-cn/library/f55ddskf%28v=vs.110%29.aspx
ServiceInstaller的对象有个属性叫ServicesDependedOn属性, 你可以把要依懒的服务名称写在里面,就OK了