我正在尝试用C#检查服务,我已添加了 System.ServiceProcess.dll
虽然我收到错误:
错误2找不到类型或命名空间名称'ServiceController'(您是否缺少using指令或程序集引用?)D:\ App\Form1.cs 247 13 App
我的代码如下:
private void button13_Click(object sender, EventArgs e)
{
    ServiceController sc = new ServiceController("Spooler");
    if (sc.Status == ServiceControllerStatus.Running)
    {
        MessageBox.Show("The service is running.");
    }
}
我是否需要"使用"声明?
专业提示:当您尝试使用.NET Framework中的类时,您会收到如下消息:
找不到类型或命名空间名称"..."(您是否缺少using指令或程序集引用?)
在MSDN Library中查找类型,并在"继承层次结构"部分下查找所需的命名空间和程序集.
继承层次结构
System.Object   
  System.MarshalByRefObject  
    System.ComponentModel.Component  
      System.ServiceProcess.ServiceController  
命名空间:  System.ServiceProcess 
程序集:   System.ServiceProcess(在System.ServiceProcess.dll中)
然后确保您具有对程序集的引用和命名空间的using指令(假设您不想完全限定名称).
| 归档时间: | 
 | 
| 查看次数: | 16342 次 | 
| 最近记录: |