Capturing the main thread SynchronizationContext or Dispatcher from a library
问题 I have a C# library that would like to have the ability to Send/Post work to the "main" ui thread (if one exists). This library may be used by: A winforms application A native application (with UI) A console application (with no UI) In the library I'd like to capture something (A SynchronizationContext, a Dispatcher, a Task Scheduler, or something else) during initialization, that will allow me to (at a later time) Send/Post work to the main thread (if the main thread has that ability--i.e.