Hi everyone,
Is it safe to call a GUI control's members directly from another thread.
That is, if I launch a background thread when the user clicks a button on my
form, can I safely retrieve info from one of its controls on that thread. I
assume that behind the scenes the call will occur back on the GUI thread
which should be fine since I have a "Work in progress" dialog running at the
time (so its message pump can handle the cross-thread call accordingly).
AFAIK then, synchronization shouldn't be an issue under these circumstances.
Can someone confirm this is safe. Thanks for your help. 3 2411
OK... no.
If you aren't on the GUI thread, you cannot do this. Just because your
user can't do anything doesn't change it; the user is not the only
thing using that thread. In fact, only a slim minority of the events
that a form gets are directly caused by the user.
In 2.0 the implementation will (correctly) catch you doing this and
snigger at you (right before it throws an exception at your background
thread); so you must either use Invoke/BeginInvoke to get back at the
UI thread, else obtain the information you need *first* (before
starting the second thread).
Marc
It is not safe. Use the BackgroundWorker component, which uses BeginInvoke
and EndInvoke to marshal an object to the UI thread, then execute it's
parameters there, usually info to update progress bars, text, etc.
"Jake Weller" <no_spam@_nospam.comwrote in message
news:eZ**************@TK2MSFTNGP05.phx.gbl...
Hi everyone,
Is it safe to call a GUI control's members directly from another thread.
That is, if I launch a background thread when the user clicks a button on
my form, can I safely retrieve info from one of its controls on that
thread. I assume that behind the scenes the call will occur back on the
GUI thread which should be fine since I have a "Work in progress" dialog
running at the time (so its message pump can handle the cross-thread call
accordingly). AFAIK then, synchronization shouldn't be an issue under
these circumstances. Can someone confirm this is safe. Thanks for your
help.
"Chris Bordeman"
<RE*********************************************** ***@hhoottmmaaiill.com>
wrote in message news:eo**************@TK2MSFTNGP04.phx.gbl...
It is not safe. Use the BackgroundWorker component, which uses
BeginInvoke and EndInvoke to marshal an object to the UI thread, then
execute it's parameters there, usually info to update progress bars, text,
etc.
Thanks for the feedback. I already am using the "BackgroundWorker" component
but need to read data from my form on the worker thread. The form itself is
completely off-limits to the user during this time since a "work in
progress" (modal) dialog sits on top of it while my thread runs (as
mentioned earlier). You're saying this still isn't safe though? I've read
the following: http://msdn2.microsoft.com/en-us/library/ms171728.aspx
and I'm not receiving the "InvalidOperationException" exception they refer
to. Ok, maybe it's potentially dangerous anyway (not sure which is why I'm
here) but given that I'm only reading (not writing) data from a dialog that
can't be altered by the user during this time (only by my worker thread),
you're still saying it's not safe? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Web Science |
last post by:
Site and Features: http://www.eigensearch.com
Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
|
by: * ProteanThread * |
last post by:
but depends upon the clique:
...
|
by: rollasoc |
last post by:
Hi,
Doing a bit of system testing on a Windows 98 laptop. (.Net 1.1 app).
Did a bit of testing. Loaded a previously saved file. A gray box
appeared with the text and buttons all white...
|
by: Web Science |
last post by:
Site and Features: http://www.eigensearch.com
Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
|
by: David Peach |
last post by:
Hello, hope somebody here can help me... I have a query that lists
defects recorded in a user defined date range. That query is then used
as the source for a Cross Tab query that cross-tabs count...
| |
by: Jeff Rodriguez |
last post by:
Here's what I want do:
Have a main daemon which starts up several threads in a Boss-Queue structure.
From those threads, I want them all to sit and watch a queue. Once an entry
goes into the...
|
by: Web Science |
last post by:
Site and Features: http://www.eigensearch.com
Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
|
by: Scott M. |
last post by:
How can I disable the cross-site scripting check for one particular page of
a site?
|
by: Rob Woodworth |
last post by:
Hi,
I'm having serious problems getting my report to work. I need to
generate a timesheet report which will contain info for one employee between
certain dates (one week's worth of dates). I...
|
by: ampo |
last post by:
Hello.
Can anyone help with cross-domain problem?
I have HTML page from server1 that send xmlHTTPRequest to server2.
How can I do it?
Thanks.
|
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: 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: 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: 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,...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
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...
| |