SynchronizationContext.Post to UI Method

后端 未结 2 510
我在风中等你
我在风中等你 2020-12-11 17:54

I\'m working with web services so its necessary for me to extend session length/reconnect and get large datasets back etc. Sometimes this can be lengthy so I wanted it in a

2条回答
  •  难免孤独
    2020-12-11 18:46

    You need a delegate of type SendOrPostCallback. Which is pretty awkward, it only takes a single argument of type object. You definitely ought to look at the Task<> class available in .NET 4 to make this easier. Or use a lambda, like this:

            string conn_name = "foo";
            uiContext.Post(new SendOrPostCallback((o) => {
                updateConnStatus(conn_name, true);
            }), null);
    

    The code between the { braces } executes on the UI thread.

提交回复
热议问题