问题描述
这是在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'不存在 命名空间'系统'(是否缺少程序集引用?)
出了什么问题?
推荐答案
<$c$c>System.ServiceProcess$c$c>命名空间是属于对 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库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!