标签:
向你运行 OnStart 和 OnStop 方法的服务添加一个方法:
internal void TestStartupAndStop(string[] args)
{
this.OnStart(args);
Console.ReadLine();
this.OnStop();
}
按如下所示重写 Main 方法:
static void Main(string[] args)
{
if (Environment.UserInteractive)
{
MyNewService service1 = new MyNewService(args);
service1.TestStartupAndStop(args);
}
else
{
// Put the body of your old Main method here.
}
在项目属性的“应用程序”选项卡中,将“输出类型”设置为“控制台应用程序”。
选择“启动调试”(F5)。
若要将该程序再次作为 Windows 服务运行,请安装它并像通常启动 Windows 服务一样启动它。 不必恢复这些更改。
标签:
原文地址:http://www.cnblogs.com/llcdbk/p/4293244.html