IssueRaiser

"Not worrying about the thread" is actually a feature of TPL.

"Not worrying about the thread" is actually a feature of TPL. A SynchronizationContext[1] is stored in thread local storage for UI threads, which can be used to queue calls back to that thread (a .Net 2.0 feature). When you `await` something, TPL takes advantage of the original SynchronizationContext and the callback will be automatically made on the UI thread. If you implement SynchronizationContext and set it, you can actually have the TPL call back into whatever special threading stuff you want. It doesn't work for WPF bindings, but for the quick'n'dirty procedural UI code it works great. [1]: https://msdn.microsoft.com/en-us/library/system.threading.sy...

Posted by zamalek on Feb 27, 2015, 8:19 AM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.7,500 issues0 comments

ux (Other)

"Not worrying about the thread" is actually a feature of TPL.

zamalekFeb 27, 2015, 8:19 AM

"Not worrying about the thread" is actually a feature of TPL. A SynchronizationContext[1] is stored in thread local storage for UI threads, which can be used to queue calls back to that thread (a .Net 2.0 feature). When you `await` something, TPL takes advantage of the original SynchronizationContext and the callback will be automatically made on the UI thread. If you implement SynchronizationContext and set it, you can actually have the TPL call back into whatever special threading stuff you want. It doesn't work for WPF bindings, but for the quick'n'dirty procedural UI code it works great. [1]: https://msdn.microsoft.com/en-us/library/system.threading.sy...

Comments (0)

No comments yet. Start the discussion.

Comment on this issue