By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,515 Members | 1,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,515 IT Pros & Developers. It's quick & easy.

Question about thread safety...

P: n/a
I have a question about thread safety in a VB application written using Visual
Studio.Net 2003.

Here is the situation...

I am running a process thread in a modal dialog. I have written it so the user
cannot exit the dialog until the thread completes (unless they click a button
to explicitly interrupt and destroy the thread).

My question...

How concerned should I be about accessing the dialog's member variables from
within the process thread? These are variables that cannot themselves be
changed anywhere on the modal dialog window.

Thanks,

Dennis
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
How concerned should I be about accessing the dialog's member variables from
within the process thread? These are variables that cannot themselves be
changed anywhere on the modal dialog window.


If you mean members for non-UI objects it shouldn't be a problem, as
long as you use appropriate synchronization.
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #2

P: n/a
On Thu, 22 Sep 2005 20:57:49 +0200, Mattias Sjögren
<ma********************@mvps.org> wrote:
How concerned should I be about accessing the dialog's member variables from
within the process thread? These are variables that cannot themselves be
changed anywhere on the modal dialog window.


If you mean members for non-UI objects it shouldn't be a problem, as
long as you use appropriate synchronization.


Yes, that is what I mean.

1> What would I have to synchronize against if the user can't do anything to
update these member variables?

2> How would you synchronize them? I saw an example that provided access thru
a Property with surrounding SyncLock Me statements. Is that the best method?

kowallek iglou com
@ .
Nov 21 '05 #3

P: n/a
On Thu, 22 Sep 2005 20:57:49 +0200, Mattias Sjögren
<ma********************@mvps.org> wrote:
How concerned should I be about accessing the dialog's member variables from
within the process thread? These are variables that cannot themselves be
changed anywhere on the modal dialog window.


If you mean members for non-UI objects it shouldn't be a problem, as
long as you use appropriate synchronization.


What if I were talking about UI objects?
--

Dennis Kowallek
kowallek{0}iglou{1}com, "@", "."
Nov 21 '05 #4

P: n/a

Dennis wrote:
On Thu, 22 Sep 2005 20:57:49 +0200, Mattias Sjögren
<ma********************@mvps.org> wrote:
How concerned should I be about accessing the dialog's member variablesfrom
within the process thread? These are variables that cannot themselves be
changed anywhere on the modal dialog window.


If you mean members for non-UI objects it shouldn't be a problem, as
long as you use appropriate synchronization.


What if I were talking about UI objects?


You cannot safely access any UI objects from a thread other than the
main UI thread. That means you'll have to use the
ISynchronizeInvoke.Invoke method, which is implemented by Form and
Control, to marshal the execution of a method from your worker thread
to the main UI thread if UI objects need to be updated.

Brian

Nov 21 '05 #5

P: n/a
On 22 Sep 2005 18:56:14 -0700, "Brian Gideon" <br*********@yahoo.com> wrote:
You cannot safely access any UI objects from a thread other than the
main UI thread. That means you'll have to use the
ISynchronizeInvoke.Invoke method, which is implemented by Form and
Control, to marshal the execution of a method from your worker thread
to the main UI thread if UI objects need to be updated.


OK. But what if I don't want to update a UI object from the worker thread? If
I only want to get a value from the UI object, can I access it? This
particular UI object happens to be disabled while the worker thread is
running.
--

Dennis Kowallek
"kowallek{0}iglou{1}com", "@", "."
Nov 21 '05 #6

P: n/a

Dennis wrote:
On 22 Sep 2005 18:56:14 -0700, "Brian Gideon" <br*********@yahoo.com> wrote:
You cannot safely access any UI objects from a thread other than the
main UI thread. That means you'll have to use the
ISynchronizeInvoke.Invoke method, which is implemented by Form and
Control, to marshal the execution of a method from your worker thread
to the main UI thread if UI objects need to be updated.


OK. But what if I don't want to update a UI object from the worker thread? If
I only want to get a value from the UI object, can I access it? This
particular UI object happens to be disabled while the worker thread is
running.


No. The read might be inconsistent since it could happen when the
control is modifying its internal state. Unless it's documented
somewhere I would not assume that a disabled control isn't responding
to windows messages and thus could be changing its internal state. I
suspect in most cases it would actually be okay though.

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.