我正在尝试将一个控制台应用程序转换为Windows服务。我想让服务的OnStart方法调用我的类中的一个方法,但是我似乎无法使它正常工作。我不确定自己是否做对了。请问在服务中应该把类信息放在哪里?
protected override void OnStart(string[] args)
{
EventLog.WriteEntry("my service started");
Debugger.Launch();
Program pgrm = new Program();
pgrm.Run();
}
来自评论:
namespace MyService {
static class serviceProgram {
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main() {
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] {
new Service1()
};
ServiceBase.Run(ServicesToRun);
}
}
}
ServiceBase.Run
? - Trevor Elliott