Windows服务编译问题 [英] Windows Service Compilation problem
问题描述
using System;
public class MyMainServiceClass
{
private System.ComponentModel.Container components = null;
private MyMainServiceClass m_mainApp;
public MyMainServiceClass ()
{
InitializeComponent ();
CanHandlePowerEvent = true;
m_mainApp = new MyMainServerAppClass ();
}
static void Main ()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[]
{
new MyMainServiceClass()
};
System.ServiceProcess.ServiceBase.Run (ServicesToRun);
}
protected override void Dispose (bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose ();
}
}
base.Dispose (disposing);
}
protected override void OnStart (string[] args)
{
m_mainApp.Start ();
}
protected override void OnStop ()
{
m_mainApp.Stop ();
}
protected override bool OnPowerEvent (PowerBroadcastStatus powerStatus)
{
switch (powerStatus)
{
case PowerBroadcastStatus.QuerySuspend:
return (true);
case PowerBroadcastStatus.Suspend:
m_mainApp.Stop ();
break;
case PowerBroadcastStatus.ResumeAutomatic:
case PowerBroadcastStatus.ResumeCritical:
case PowerBroadcastStatus.ResumeSuspend:
m_mainApp.Start ();
break;
default:
break;
}
base.OnPowerEvent (powerStatus);
return (true);
}
private void InitializeComponent ()
{
components = new System.ComponentModel.Container ();
this.ServiceName = "MyVS.NetService";
}
}
问题:我正在尝试在visual studio.plz中提供Windows服务,请告诉我如何使用PowerBroadcastStatus.必须公开声明它可能正在使用枚举类,但我没有得到如何做.我以某种方式进行了研究,在代码中做了 BOLD 行,并做了很多工作,但是一个问题来了,编译器说找不到命名空间名称PowerBroadcastStatus.请帮助我.谢谢
[edit author ="rjm"]
删除了虚假标签(C ++,C,VB,CSS,Java),因为这显然是C#,并且整理了格式.
[/edit]
QUESTION: I am trying to make a windows service in visual studio.plz tell me how to use PowerBroadcastStatus.it has to be declared publically may be using enum class but i am not getting how to do it. Doing research i somehow made the BOLD line in the code and done a lot of work in it but one issue is coming, the compiler says namespace name PowerBroadcastStatus could not be found. Kindly help me with it. Thanks
[edit author="rjm"]
Removed spurious tags (C++, C, VB, CSS, Java) as this is clearly C#, and tidied formatting.
[/edit]
推荐答案
此处: ^ ]& .NET 4.0:PowerBroadcastStatus枚举 [
Here: .NET 2.0: PowerBroadcastStatus Enumeration[^] & .NET 4.0: PowerBroadcastStatus Enumeration[^]
It indicates the system''s power status. It is under namespace:System.ServiceProcess
& assembly:System.ServiceProcess
(in System.ServiceProcess.dll)
Make sure there is a reference of above said assembly.
这篇关于Windows服务编译问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!