Re: Is this safe

Tech-Archive recommends: Speed Up your PC by fixing your registry



I have a worker thread that may need to display a dialog for the user. Is
it safe for the worker thread to invoke the form's constructor and then
pass the form's reference to the main GUI thread where "ShowDialog()"
will then be invoked. I assume it probably is since the form is never
displayed on the actual worker thread. Can someone confirm this is safe.
Thanks.

I don't think you can assume that it's safe. Whether it's safe depends on
whether the dialog's window handle has been created, and exactly when the
window handle is created depend on exactly how the dialog is accessed,
including potentially from code that runs in the constructor of the form.

I'm prepared to be wrong about that :) I suspect that it is in fact safe
in many cases, but I wouldn't bank on it.

Thanks for the feedback. I'm the one who's authoring this form however and
the constructor will always perform simple initialization only (no window
handles are ever created). Since the form is originally created by the VS
form's designer however, I can't be sure what "InitializeComponent()" will
do. I seriously doubt that it ever deals with windows handles however (this
is a constructer after all) but you never know. Hopefully someone can
clarify the situation. Anyway, thanks again.


.



Relevant Pages

  • Re: Is this safe
    ... Is it safe for the worker thread to invoke the form's constructor and ... form is never displayed on the actual worker thread. ... this is safe. ... the window handle is created depend on exactly how the dialog is ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Is this safe
    ... I have a worker thread that may need to display a dialog for the user. ... it safe for the worker thread to invoke the form's constructor and then ... Can someone confirm this is safe. ... including potentially from code that runs in the constructor of the form. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: output.c error in multithreaded program
    ... I agree that it is possible to create a system that is perfectly safe. ... When the target is a window created by a different ... >in the GUI thread has no effect on the worker thread WRT to the sent message ...
    (microsoft.public.vc.mfc)
  • Re: 2.0 USB Use locks up Windows XP
    ... I have to thank you for the suggestion to uninstall in the safe ... But the USB's did work with a camera and USB mouse so I ... The window that pops up indicates there are 2.0 USB’s ... Safe Mode and uninstall *all* listings under 'Universal Serial Bus ...
    (microsoft.public.windowsxp.newusers)
  • Re: Transfering data from one window to another
    ... Create a new global field <gMemberID> ... This uses the actual id and stores it in a safe place to be re-used. ... I have a button that opens a new window ... member ID field on the new note window. ...
    (comp.databases.filemaker)