这是我的 Windows 服务代码......但不幸的是,方法 myTimer_Elapsed() 仅在至少 60 秒时被调用。启动服务后。为什么切换服务后不立即启动?
public partial class MyService : ServiceBase
{
private System.Threading.Thread myWorkingThread;
private System.Timers.Timer myTimer = new System.Timers.Timer();
protected override void OnStart(string[] args)
{
myWorkingThread = new System.Threading.Thread(PrepareTask);
myWorkingThread.Start();
}
private void PrepareTask()
{
myTimer.Elapsed += new System.Timers.ElapsedEventHandler(myTimer_Elapsed);
myTimer.Interval = 60000;
myTimer.Start();
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
}
void myTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
..my code to prepare binary db files
BinaryDB rdr = new BinaryDB();
rdr.ReadFile(...)
}
}