I am currently developing an application, I would like to implement a time delay. I don’t want to use System.Threading.Thread.Sleep(x); as I read this stalls the thread (UI freezes)
The code I have currently written is:
public void atimerdelay()
{
lblStat.Text = "In the timer";
System.Timers.Timer timedelay;
timedelay = new System.Timers.Timer(5000);
timedelay.Enabled = true;
timedelay.Start();
}
I know atimerdelay() does get called (using lblStat), but their is no delay of 5 seconds. I have read http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx but I can’t work out why the above code is not working.
Additional information – (added for Hamlet Hakobyan)
The application is a ‘card checker’ application (University project – no real information is used or stored). Once the user has filled out all the relevant and click ‘check’ a list of validation methods are called. Before any of these are called a ping is carried out to make sure a live internet connection is on the computer. I want to add a slight delay between the ping and the starting of the validation.
How about:
? It won’t block UI thread and looks pretty good!