为什么我的C#没有System.ServiceProcess库?我的、System、ServiceProcess

由网友(南城荒凉北城伤)分享简介:这是在code。我只是想测试System.ServiceProcess库的库。This is the code. I just wanna test the library of System.ServiceProcess library.using System;using System.Collections...

这是在code。我只是想测试System.ServiceProcess库的库。

This is the code. I just wanna test the library of System.ServiceProcess library.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceProcess;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("hi");
            var srv = new ServiceController("MyService");
            Console.WriteLine("MyService Status {0}", srv.Status);
            if (srv.Status != ServiceControllerStatus.Running)
                srv.Start();
            System.Threading.Thread.Sleep(1000000);
        }
    }
}

然而,当我运行C#code,它说:

However, when I run the C# code, its says:

错误1类型或命名空间名称ServiceProcess'不存在   命名空间'系统'(是否缺少程序集引用?)

Error 1 The type or namespace name 'ServiceProcess' does not exist in the namespace 'System' (are you missing an assembly reference?)

出了什么问题?

推荐答案

System.ServiceProcess命名空间是属于对 System.ServiceProcess.dll ,它并没有添加作为参考默认。

System.ServiceProcess namespace belongs on System.ServiceProcess.dll and it doesn't added as a reference by default.

对于这一点,在溶液中窗口中,右键单击引用,并选择添加引用...转至.NET选项卡,然后双击的 System.ServiceProcess.dll 的

For this, in the solution window, right click on "References" and choose "Add Reference.." Go to the .NET tab, and double click on System.ServiceProcess.dll.

这个组件可能是在 C: WINDOWS Microsoft.NET 框架 V2.0.50727 文件夹

This assembly is probably in C:WINDOWSMicrosoft.NETFrameworkv2.0.50727 folder.

阅读全文

相关推荐

最新文章