Windowsサービスのタイマーに奇妙な問題があります。私の最初のWindowsサービスなので、開始するには、10秒ごとに.txtファイルに書き込むサービスを作成することに決めました。 私はタイマーを追加しますが、タイマーが起動しないようです。 私はどこが間違っているのか理解できるように助けてくれますか? ここに私のコード:タイマーとWindows Serice c#
namespace testtimer
{
public partial class TestTimer : ServiceBase
{
public TestTimer()
{
InitializeComponent();
timer.Interval = 10000;
timer.Enabled = true;
}
protected override void OnStart(string[] args)
{
timer.Start();
}
protected override void OnStop()
{
}
private void timer_Tick(object sender, EventArgs e)
{
string date = System.DateTime.Now.ToString();
StreamWriter wr = new StreamWriter(@"C:\Users\xxx\Desktop\Test\testtimer.txt", true);
wr.WriteLine("\n" + "The Time is:" + "\t" + date);
wr.Close();
}
}
}
私は間違っていますか?あなたの助けのための
おかげでたくさん:)
timer.Tick + = timer_Tick。おそらく? – linuxrocks