Hi,
I have a GUI application that responds to events coming from an externaql
application. In the implementing code for the event I need to create a GUI
control and "parent" the control into the GUI. Doing this directly fails, it
is not allowed to parent a control that was not created on the main GUI
thread into the main GUI through another thread (an exception is thrown on
"control.Parent = container;").
So I have to create the control on the main thread but I don't want to
create a pool of controls upfront because there is no telling how many I
will need (it depends on the type of events that may be recieved).
So, the control needs to be created on the main thread yet this action has
to be initiated just in time from the external thread. In any Win32
application I would implement the control creation code in a message handler
of the main form, invoke it using SendMessage with WM_COMMAND and some
custom message from the other thread and retrieve the control pointer
through a private variable in the main form.
Now I could import SendMessage and hack around with some handles but I would
rather do it the .NET way.
What is the .NET way?
Regards,
Martin.