Hacker News new | past | comments | ask | show | jobs | submit login

"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...




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: