I've got the following program flow in my Windows Forms application (WPF is not a viable option unfortunately):
- The GUI Thread creates a splash screen and a pretty empty main window, both inheriting
Form. - The splash screen is shown and given to
Application.Run(). - The splash screen will send an event which triggers an
asyncEvent Handler which performs initialization, using theIProgressinterface to report progress back to the GUI. (This works flawlessly.) - At some point during the initialization, I need to dynamically create GUI components based on information provided by certain plugins and add them to the Main Window.
At this point I'm stuck: I know I need to ask the GUI thread to create those components for me, but there is no Control I could call InvokeRequired on. Doing MainWindow.InvokeRequired works neither.
The only idea I could come up with was to fire an event which is connected to a factory in the GUI Thread, and then wait for that factory to fire another event which provides the created controls. However I am pretty sure there is a more robust solution. Does anyone know how to achieve this?