コードの一部を実行するWindowsサービスを作成し、タイマーを実装して定期的に実行します。
私のタイマークラスは:
class TimerClass
{
private static System.Timers.Timer aTimer;
public static void Main()
{
aTimer = new System.Timers.Timer(1000);
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
aTimer.Interval = 5000;
aTimer.Enabled = true;
GC.KeepAlive(aTimer);
}
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
aTimer.Stop();
DatabaseUpdation dbUp = new DatabaseUpdation();
File.AppendAllText(@"C:\Documents and Settings\New Folder\My Documents\demo\abc.txt", "Start" + " " + DateTime.Now.ToString() + Environment.NewLine);
dbUp.GetDatafromSource();
aTimer.Start();
}
}
そして、私はそれを私のStartメソッドから呼び出しています:
protected override void OnStart(string[] args)
{
TimerClass timer = new TimerClass();
}
しかし、タイマーはまったく実行されていません。誰かが私にここで間違いを見つけることができますか?前もって感謝します