嘿家伙,我已经在网上关于一些关于创建和安装Windows服务的教程,似乎不断陷入困境。我遵循教程here,它似乎在工作,但它不是100%。这是使用代码IM:坚持实施Windows服务
namespace SuperService
{
partial class Logger : ServiceBase
{
public Logger()
{
InitializeComponent();
}
void timer1_Tick(object sender, EventArgs e)
{
LogEvent("This Timer has been ticked!", EventLogEntryType.Information);
}
protected override void OnStart(string[] args)
{
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Start();
LogEvent("This SuperService has started!", EventLogEntryType.Information);
}
protected override void OnStop()
{
LogEvent("This SuperService has stopped.", EventLogEntryType.Information);
}
protected override void OnPause()
{
base.OnPause();
timer1.Stop();
}
protected override void OnContinue()
{
base.OnContinue();
timer1.Start();
}
static void LogEvent(String Message, EventLogEntryType type)
{
String source = "Logger";
String log = "Application";
if (!EventLog.SourceExists(source))
{
EventLog.CreateEventSource(source, log);
}
EventLog eLog = new EventLog();
eLog.Source = source;
eLog.WriteEntry(Message, type);
}
}
}
现在,当我启动服务它显示了以下两个事件后检查事件查看器:
这SuperService已经开始了!
服务已成功启动。
所以它似乎有点工作,我没有看到是由timer1_Tick触发的事件。有谁知道为什么或可以指出我在正确的方向吗?提前致谢。
定时器的间隔是多少?确保它不是0. – 2010-08-19 20:43:56
定时器的间隔在哪里设置?也许在设计师?它有什么价值? – 2010-08-19 20:45:20
其60000和启用 – 2010-08-19 20:45:46