When I click on a button in Silverlight I want to run a method 2 seconds later once only for each time I click the button .. in the meantime the rest of the app keeps working .. obviously Thread.Sleep stops the whole UI .. how do I do this?
+1
A:
Inside handler start a new thread that will wait 2 seconds and execute your method. I mean something like
public void button_click(...)
{
(new Thread( (new ThreadWorker).DoWork).Start();
}
public class ThreadWorker
{
public void DoWork() { Thread.Sleep(2); RunMyCustomMethod();}
}
tchrikch
2010-10-29 07:19:24
Instead of declaring a custom worker class, it is possible to leverage BackgroundWorker for this kind of operations as well.(http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker(v=VS.95).aspx)
Murven
2010-10-29 13:01:13
@Murven good point, that's also an option
tchrikch
2010-10-29 13:30:17