WPF/C# Don't block the UI

后端 未结 6 1205
再見小時候
再見小時候 2020-12-20 03:11

I\'ve an existing WPF application, which has several sections. Every section is a UserControl, that implements an interface.

The interface specify two methods:

6条回答
  •  眼角桃花
    2020-12-20 03:42

    You probably should use TPL if your framework version is 4.0:

    var uiScheduler = TaskScheduler.FromCurrentSynchronizationContext(); // this will work only if you're running this code from UI thread, for example, by clicking a button
    Task.Factory.StartNew(() => UnloadData()).ContinueWith(t => /*update ui using t.Result here*/, uiScheduler);
    

    Hope this helps.

提交回复
热议问题