いくつかの条件に基づいてユーザーにメールを送信する Windows サービスを作成しました。自動モードでサーバーにインストールしました。ログから、初めて正常に実行されて終了したことがわかります。
その後、ログで再び実行されているのを見ませんでした。
管理ツールでサービスを確認したところ、開始されていると表示されます。
サービスも再起動しましたが、使用できませんでした。再起動しませんでした。
以下は、サービスを開始するために使用したコードです。
public partial class ScheduledService : ServiceBase
{
Timer timer;
private DateTime lastRun = DateTime.Now;
private DateTime DailyRunTime = Convert.ToDateTime(System.Configuration.ConfigurationManager.AppSettings["DailyRunTime"]);
public ScheduledService()
{
InitializeComponent();
//GetDocRetentionList DocList = new GetDocRetentionList();
//DocList.GetDataSet();
}
protected override void OnStart(string[] args)
{
//System.Diagnostics.Debugger.Launch();
TraceService("start service");
//timer = new Timer(24 * 60 * 60 * 1000);
timer = new Timer(10 * 60 * 1000);
timer.Start();
timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
double TimerInterval = Convert.ToDouble(System.Configuration.ConfigurationManager.AppSettings["Timer"]);
timer.Interval = TimerInterval;
timer.Enabled = true;
}
protected override void OnStop()
{
timer.Enabled = false;
TraceService("stopping service");
}
private void OnElapsedTime(object source, ElapsedEventArgs e)
{
TraceService("Service started at " + DateTime.Now);
if (lastRun.Date < DateTime.Now.Date)
{
if (DateTime.Now > DailyRunTime)
{
GetDocRetentionList DocList = new GetDocRetentionList();
DocList.GetDataSet();
timer.Stop();
lastRun = DateTime.Now.Date;
//timer.Start();
}
}
}
この点で私が得ることができるどんな助けも本当に役に立ちます. 教えてください。