加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 无法找到类型或命名空间名称“ServiceController”

发布时间:2020-12-15 03:46:13 所属栏目:百科 来源:网络整理
导读:我试图在C#中检查一个服务,我添加了System.ServiceProcess.dll 虽然我收到错误: Error 2 The type or namespace name ‘ServiceController’ could not be found (are you missing a using directive or an assembly reference?) D:AppForm1.cs 247 13 Ap
我试图在C#中检查一个服务,我添加了System.ServiceProcess.dll

虽然我收到错误:

Error 2 The type or namespace name ‘ServiceController’ could not be found (are you missing a using directive or an assembly reference?) D:AppForm1.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.");
    }
}

我可能需要一个“使用”声明?

解决方法

您需要添加对System.ServiceProcess.dll的引用

之后,您将可以在Visual Studio中看到它,作为您可以添加到项目的使用语句之一:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读