Hi, I'm trying to have my app wait for a while, just doing nothing, without blocking my GUI from being responsive to keyboard and mouse events. Using Thread.Sleep(X) will block, so I'm trying to have a second thread to wait.

I'm either a very bad searcher, or there isn't much out there on the subject!! Everyone just goes for Thread.Sleep(X) ...
(I did find this article though, which I found very interesting)

What I'm trying is to have a second thread do the "sleeping" while the main thread "does events" until the waiting is done. For that, I have the following class:

Code:
using System.Threading;

public static class Timers
{
	static double delayCount;

	public static void Delay(double miliseconds)
	{
		delayCount = miliseconds;

		BackgroundWorker worker = new BackgroundWorker();
		worker.DoWork += new DoWorkEventHandler(worker_DoWork);
		worker.RunWorkerAsync();

		while (worker.IsBusy)
		{
			Application.DoEvents();
			Thread.Yield();
		}
		worker.Dispose();
	}

	static void worker_DoWork(object sender, DoWorkEventArgs e)
	{
		System.Windows.Forms.Timer waiter = new System.Windows.Forms.Timer();
		waiter.Interval = (int)delayCount;
		waiter.Tick += new EventHandler(waiter_Tick);
		waiter.Start();
		while (waiter.Enabled) { }
		waiter.Dispose();
	}
	static void waiter_Tick(object sender, EventArgs e)
	{
		((System.Windows.Forms.Timer)sender).Stop();
	}
}
The problem with it is that the Tick event never happens, thus the timer never stops, the worker never finishes its work, and finally my app ends up waiting forever.

I'm creating the timer inside the worker because if Ï do it from the Delay function it will block. Add a mouse move event to any object on the main form and you'll be able to check if it blocks very easily. A big blank form with a label and an update mouse coordinates event will do.

Does anyone know where to find information on this? Or ideas on how to do it?
Thank you in advance!