12,166
社区成员




//百度说这个声明必须放在外部,否则会被垃圾回收
private System.Threading.Timer tMain = null;
private void ReadDev( object obj )
{
//释放tMain占用的资源
tMain.Dispose();
//。。。屏蔽的业务代码
tMain = new System.Threading.Timer( ReadDev, null, 10000, 0 );
}
//百度说这个声明必须放在外部,否则会被垃圾回收
private System.Threading.Timer tMain = null;
private void ReadDev( object obj )
{
//释放tMain占用的资源
tMain.Dispose();
//。。。屏蔽的业务代码
while ( /*需要重新开始ReadDev的条件*/ ) {
//。。。屏蔽的业务代码
Thread.Sleep( 10000 );
}
tMain = new System.Threading.Timer( ReadDev, null, 10000, 0 );
}
//百度说这个声明必须放在外部,否则会被垃圾回收
private System.Threading.Timer tMain = null;
private void ReadDev( object obj )
{
//。。。屏蔽的业务代码
}
protected override void OnStart( string[] args ) {
logMain.WriteEntry( "启动服务", EventLogEntryType.Information );
//服务启动5分钟后才开始工作,为了防止比依赖服务启动的早。
tMain = new System.Threading.Timer( ReadDev, null, 300000, 10000 );
}