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 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.
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
@ .
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, "@", "."
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
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", "@", "."
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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?
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |