S
Steve Sargent
Hi:
I'm running a chat application that when called by a remote caller, opens a chat window. Currently,
I'm using Application.Run() to create each new window, because I am having problems accessing the
window from the non-gui thread. However, I imagine this is very resource intensive, and would
rather find a cleaner approach, if possible.
In testing possible scenarios, I've noted that a form instantiated inside the constructor of the
main window can be called (invoked, actually) from a different thread....if it has already been
shown before. By that, I mean if a call to show has been placed on the child form from the parent's
gui thread, then subsequent calls work out fine. In debugging, I noted that if the form hasn't
already been shown, then the first InvokeRequired call to the form comes back as false. Obviously,
this isn't true, since I do need to view the form from the thread that instantiated it.
I've tried tricks to get around this with no avail. I've set a flag up so that the first time Load
is called from the child form, it's visible flag is set to false. I've done the same with calling
hide the first time; i've combined the two. I've called Close on them (which has cancel set to true
and hide set). Then I've called them first from the parent's constructor with Show(). They child
window doesn't hide.
I've tried calling invoke directly without testing...I get an exception because the window hasn't
been created yet.
I'm running out of options.
The only other option I can think of right now is to setup an invisible button and invoke it, which
will show the window. I think....that would work...I don't know, though. I've always had problems
for some reason with the button.PerformClick() method.
Does anyone have any suggestions on ways to get the gui to do its loadup stuff without displaying
the child window, so I can call the child window from another thread safely?
Any help given is greatly appreciated.
Steve
I'm running a chat application that when called by a remote caller, opens a chat window. Currently,
I'm using Application.Run() to create each new window, because I am having problems accessing the
window from the non-gui thread. However, I imagine this is very resource intensive, and would
rather find a cleaner approach, if possible.
In testing possible scenarios, I've noted that a form instantiated inside the constructor of the
main window can be called (invoked, actually) from a different thread....if it has already been
shown before. By that, I mean if a call to show has been placed on the child form from the parent's
gui thread, then subsequent calls work out fine. In debugging, I noted that if the form hasn't
already been shown, then the first InvokeRequired call to the form comes back as false. Obviously,
this isn't true, since I do need to view the form from the thread that instantiated it.
I've tried tricks to get around this with no avail. I've set a flag up so that the first time Load
is called from the child form, it's visible flag is set to false. I've done the same with calling
hide the first time; i've combined the two. I've called Close on them (which has cancel set to true
and hide set). Then I've called them first from the parent's constructor with Show(). They child
window doesn't hide.
I've tried calling invoke directly without testing...I get an exception because the window hasn't
been created yet.
I'm running out of options.
The only other option I can think of right now is to setup an invisible button and invoke it, which
will show the window. I think....that would work...I don't know, though. I've always had problems
for some reason with the button.PerformClick() method.
Does anyone have any suggestions on ways to get the gui to do its loadup stuff without displaying
the child window, so I can call the child window from another thread safely?
Any help given is greatly appreciated.
Steve