views:

14

answers:

1

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
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
@Murven good point, that's also an option
tchrikch