A sample of using SyncronizationContext to post a message back to the UX thread

 

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    SynchronizationContext ctx = SynchronizationContext.Current;

    ThreadPool.QueueUserWorkItem(_ =>
    {

        WebClient client = new WebClient();

        string html = client.DownloadString("http://www.briankeating.net");
        ctx.Post(state =>
        {
            tbDetails.Text = (string)state;

        }, html);

    });

}

About Brian Keating
Brian Keating
Professional Software Developer, .NET / C++ / Java View all posts by Brian Keating →