您的位置:首页 > 其它

MSDN上面测试Window的方法(很好用)

2015-02-15 17:20 183 查看

如何:将 Windows 服务作为控制台应用程序运行

向你运行 OnStartOnStop 方法的服务添加一个方法:

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 服务一样启动它。 不必恢复这些更改。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: