Windows message pumb / Dispatcher / RealProxy
Not so long ago I had to integrate a COM component into an application. The catch was the application had no Windows message pumb and the COM component uses exactly this message pumb for some communications. So I need to create a thread with its own message pumb and then dispatch the calls to the component to the thread holding this message pumb. Creating a thread is simple and quickly done. _thread = new Thread(RunThread) { Name = nameof(MessagePumpDispatcher), IsBackground = true } _thread.SetApartmentState(ApartmentState.STA); _thread.Start(); And to start a new message pumb I can use the Dispatcher type. _dispatcher = Dispatcher.CurrentDispatcher; try { Dispatcher.Run(); } catch (ThreadAbortException) { Thread.ResetAbort(); } Dispatching work to this thread can be achieved by using the Invoke method on the Dispatcher. _dispatcher.Invoke(action); This is the whole class. Now to send all calls of the component to the correct class I could either wrap...