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 1137 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.o rg> 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.o rg> 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}iglo u{1}com, "@", "."
Dennis wrote: On Thu, 22 Sep 2005 20:57:49 +0200, Mattias Sjögren <ma************ ********@mvps.o rg> 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
ISynchronizeInv oke.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*********@ya hoo.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 ISynchronizeIn voke.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}igl ou{1}com", "@", "."
Dennis wrote: On 22 Sep 2005 18:56:14 -0700, "Brian Gideon" <br*********@ya hoo.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 ISynchronizeIn voke.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 threads of a multithreaded
program using embedded SQL. Since the threads do not need to share
transaction scopes, the sqleAttachToCtx family of APIs do not seem to be
necessary.
<quote>
In the default implementation of threaded applications against...
|
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
potential problems for thread-safety. So far, I'm only confused.
I need a proper explanation for the concept so I can understand how
to write thread-safe functions in the future.
My apologies for posting a long routine.
|
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 incoming connection,the relative code snipprt as following::
private IPAddress myIP=IPAddress.Parse("127.0.0.1");
private IPEndPoint myServer;
private Socket socket;
private Socket accSocket;
private System.Windows.Forms.Button button2;...
|
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 the list like
MyTyp x = aList;
aList.Remove(x);
|
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 events which are fired on an arbitrary
thread, and I then take the data, generate update commands for a SQL Server
database, and add them to a queue using a lock on a sync object to ensure
thread safety when writing to the queue.
| |
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 as a single application.
I was wondering if there is a "Thread-Safety Analysis Wizard"?
I'm sure I'm grossly off-base with the following, so I'm prepared to be
embarrassed. Please point me in the right direction!
|
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 do not want to load the config file
everytime. The problem is I am using XMLReader because of speed and after I
read an item (multiple nodes so pass node name and element name) and try to
read another item I get an error "root element missing". ...
|
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 to the client.
Before adding data to the arraylist, I check if the depth of the arraylist
is longer than iMaxQueueDepth, and if it is, I clear the arraylist.
Is it possible that while I am clearing the arraylist, the ThreadMain at the
same time...
|
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: 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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |