A Timer is the right way to do it, and they are a lot easier to use than it looks! :laugh:
All you need to do is create a Timer object, initialize it, and add a handler method.
Create:
private Timer myTimer = new Timer();
Initialize:
myTimer.Interval = 250;
myTimer.Tick += new EventHandler(myTimer_Tick);
myTimer.Start();
Handler method:
void myTimer_Tick(object sender, EventArgs e)
{
}
Whatever code you put inside the myTimer_Tick method will be executed every 250 milliseconds - or 4 times a second (that's what the value I put in the Interval property causes)
So if you want to print a string once, after a delay of ten seconds, then:
private Timer myTimer = new Timer();
private void myForm_Load(object sender, EventArgs e)
{
myTimer.Interval = 10000;
myTimer.Tick += new EventHandler(myTimer_Tick);
}
private void myButton_Click(object sender, EventArgs e)
{
myTimer.Start();
}
void myTimer_Tick(object sender, EventArgs e)
{
Console.WriteLine("Hello");
myTimer.Stop();
}
If you don't add the "Stop" call, it will repeat until your application ends.