作者atowng (阿棠)
看板C_Sharp
标题Re: [问题] 如何自订Window服务
时间Sun Jan 11 16:58:08 2009
※ 引述《atowng (阿棠)》之铭言:
: 各位先进好:
: 小弟我上网搜寻一阵子,有说可以新增专案并且使用范本里面的
: Window服务来建立专案,不过我的Visual Studio 2005是Team Suite版的,
: 所以没有这个范本可以使用,要如何自订Window服务,
: 还有要如何将写好的程式,安装为Window服务。
: 谢谢!
//=======================================================================
不好意思,是小弟我自己搞错了,确实有Window服务的范本。
我按照MSDN的说明,安装与部属了MyServier,并且启动我的服务,
不过我的程式好像没有被执行:
public partial class MyNewService : ServiceBase
{
protected override void OnStart(string[] args)
{
// TODO: 在此加入启动服务的程式码。
eventLog1.WriteEntry("In OnStart");
timer1.Interval = 300000;
timer1.Enabled = true;
}
protected override void OnStop()
{
// TODO: 在此加入停止服务所需执行的终止程式码。
eventLog1.WriteEntry("In onStop.");
}
protected override void OnContinue()
{
eventLog1.WriteEntry("In OnContinue.");
}
private void timer1_Tick(object sender, EventArgs e)
{
this.timer1.Enabled = false;
StreamWriter oSW = new StreamWriter("C:\\新文字文件 (2).txt",
true, Encoding.Default);
oSW.Write("%%%%%%%%%%%%%");
this.timer1.Enabled = true;
}
}
直觉上启动服务时timer就会被启动就会复写资料到.txt档
一直找不出原因,请教大家了。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 115.43.131.39
1F:→ regionbbs:你用 System.Timers.Timer 试看看。 01/14 20:44