我正在编写一个 Windows 10 通用应用程序。我需要在 UI 线程上运行一些特定的代码,但是一旦代码完成,我想在第一次调用请求的同一个线程上运行一些代码。请参见下面的示例:
private static async void RunOnUIThread(Action callback)
{
//<---- Currently NOT on the UI-thread
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
//Do some UI-code that must be run on the UI thread.
//When this code finishes:
//I want to invoke the callback on the thread that invoked the method RunOnUIThread
//callback() //Run this on the thread that first called RunOnUIThread()
});
}
我将如何做到这一点?