.NET: Best way to execute a lambda on UI thread after a delay?

Posted by Scott Bussinger on Stack Overflow See other posts from Stack Overflow or by Scott Bussinger
Published on 2010-04-02T05:40:16Z Indexed on 2010/04/02 5:43 UTC
Read the original article Hit count: 254

Filed under:
|
|

I had a situation come up that required running a lambda expression on the UI thread after a delay. I thought of several ways to do this and finally settled on this approach

Task.Factory.StartNew(() => Thread.Sleep(1000))
    .ContinueWith((t) => textBlock.Text="Done",TaskScheduler.FromCurrentSynchronizationContext());

But I'm wondering if there's an easier way that I missed. Any suggestions for a shorter, simpler or easier technique? Assume .NET 4 is available.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about c#