我想在.CS文件中关闭一个服务,但总是实现不了,不知道是怎么回事
我的代码如下:
if (myService != null)
  {
    if (myService.Status != ServiceControllerStatus.Stopped)
      {
          bool l = myService.CanStop;
          myService.Stop();
       }
                      //关闭服务
     }
上述代码可以执行到   myService.Stop();   ,但这一句没能关闭服务
在运行时,l = true
调试时在输出中会有:
第一個可能發生的例外狀況類型 'System.InvalidOperationException' 發生於 System.ServiceProcess.dll
第一個可能發生的例外狀況類型 'System.Reflection.TargetInvocationException' 發生於 mscorlib.dll