为什么我的C#没有System.ServiceProcess库? [英] Why my C# does not have System.ServiceProcess Library?

查看:2841
本文介绍了为什么我的C#没有System.ServiceProcess库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在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?)

出了什么问题?

推荐答案

<一个href="http://msdn.microsoft.com/en-us/library/system.serviceprocess%28v=vs.110%29.aspx"><$c$c>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:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 folder.

这篇关于为什么我的C#没有System.ServiceProcess库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆