.NET: Best way to execute a lambda on UI thread after a delay?
- by Scott Bussinger
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.