473,401 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Question about thread safety...

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
6 1123
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
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
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

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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Mark Yudkin | last post by:
The documentation is unclear (at least to me) on the permissibility of accessing DB2 (8.1.5) concurrently on and from Windows 2000 / XP / 2003, with separate transactions scope, from separate...
4
by: Jonathan Burd | last post by:
Greetings everyone, Here is a random string generator I wrote for an application and I'm wondering about the thread-safety of this function. I was told using static and global variables cause...
4
by: zbcong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting for a...
17
by: Rainer Queck | last post by:
Hi NG, one more question about thread safety of generic lists. Let's assume a generic list: List<MyTyp> aList = new List<MyType>(); Would it be a problem if one thread removes elements from...
5
by: jzlondon | last post by:
Hi, I have a question that I wonder if someone might be able to help me with... I have an application which handles real-time financial data from a third party source. The data comes in via...
4
by: Warren Sirota | last post by:
Hi, I've got a method that I want to execute in a multithreaded environment (it's a specialized spider. I want to run a whole bunch of copies at low priority as a service). It works well running...
6
by: Mitch | last post by:
Hello, I have a singleton class that loads a config file (for an assembly) into an internal stream object. I designed this class as singleton because it parses the config file many times and I...
6
by: fniles | last post by:
I am using VB.NET 2003 and a socket control to receive and sending data to clients. As I receive data in 1 thread, I put it into an arraylist, and then I remove the data from arraylist and send it...
13
by: arun.darra | last post by:
Are the following thread safe: 1. Assuming Object is any simple object Object* fn() { Object *p = new Object(); return p; } 2. is return by value thread safe?
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.