/// Get TaskScheduler to schedule Tasks on UI thread.
/// </summary>
/// <returns>TaskScheduler to schedule Tasks on UI thread.</returns>
public TaskScheduler GetUITaskScheduler()
{
return TaskSchedulerUI;
}
/// <summary>
/// Check whether current tread is UI tread
/// </summary>
/// <returns><c>true</c>if current tread is UI tread.</returns>
public bool IsOnUIThread()
{
return GuiThread == Thread.CurrentThread;
}
}
该class的要求是必须在UI thread初始化。
The requirement for the UITaskShcedulerService is that you should construct the singleton instance to start from a UI threads.
因为他内部使用的是TaskScheduler.FromCurrentSynchronizationContext,根据MSDN的TaskScheduler Class 定义 ,它拿到的是当前thread的synchronization context
Because it internally use the TaskScheduler.FromCurrentSynchronizationContext. and from the TaskScheduler Class from MSDN, it retrieve the current thread’s synchronization context.