I am writing a simple C # program that tries to do something every x seconds using System.Forms.Timer
The tick event calls a method that starts a new thread and disables the timer, and then, when the thread is running with it, it starts the timer again, but the problem is that now it does not go out after it is turned on.
static System.Windows.Forms.Timer testtimer = new System.Windows.Forms.Timer();
static void Main()
{
testtimer.Tick += testtimertick;
testtimer.Interval = 5000;
testtimer.Enabled = true;
testtimer.Start();
while (true)
{
Application.DoEvents();
}
}
private static void testtimertick(object sender, System.EventArgs e)
{
testtimer.Enabled = false;
Thread t = new Thread(dostuff);
t.Start();
}
private static void dostuff()
{
testtimer.Enabled = true;
testtimer.Start();
}
source
share