Re: Is this safe
- From: "Michael Chambers" <no_spam@xxxxxxxxxxx>
- Date: Mon, 2 Oct 2006 19:49:46 -0400
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.
.
- Follow-Ups:
- Re: Is this safe
- From: Brian Gideon
- Re: Is this safe
- From: Carl Daniel [VC++ MVP]
- Re: Is this safe
- References:
- Is this safe
- From: Michael Chambers
- Re: Is this safe
- From: Carl Daniel [VC++ MVP]
- Is this safe
- Prev by Date: Re: Is this safe
- Next by Date: Re: Thread-safety analyzer/simple guidelines
- Previous by thread: Re: Is this safe
- Next by thread: Re: Is this safe
- Index(es):
Relevant Pages
|