473,503 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

updating a window from another thread

I have a Form based dialog which kicks off a worker
thread. The form has a progress bar, and a Cancel
button. The Cancel button Aborts the thread, and when
exiting, the thread attempts to Show a hidden control on
the form. This does not work, and I'm pretty sure it's
because the Show method is being called from a different
thread. Closer inspection of the documentation for Form
and the various controls confirms this. (Static members
are threadsafe, but instance members are not).

The worker thread also updates the progress bar directly
on the Dialog, and athough this is working, I now believe
that I shouldn't be doing this. Am I correct?

In the C++ world, I would have posted a user message to
the form, but I can't find anything similar in .NET.

How can I update by Dialog from the worket thread in a
threadsafe manner.

Thanks

Nov 15 '05 #1
1 6678

"Ron James" <Ro*******@nospam.rojacs.com> wrote in message
news:03****************************@phx.gbl...
I have a Form based dialog which kicks off a worker
thread. The form has a progress bar, and a Cancel
button. The Cancel button Aborts the thread, and when
exiting, the thread attempts to Show a hidden control on
the form. This does not work, and I'm pretty sure it's
because the Show method is being called from a different
thread. Closer inspection of the documentation for Form
and the various controls confirms this. (Static members
are threadsafe, but instance members are not).

The worker thread also updates the progress bar directly
on the Dialog, and athough this is working, I now believe
that I shouldn't be doing this. Am I correct?

In the C++ world, I would have posted a user message to
the form, but I can't find anything similar in .NET.

How can I update by Dialog from the worket thread in a
threadsafe manner.


You can use the Invoke() method that exists on every
Windows Form control.

You define a method in your form that does what you
want it to do, then define a delegate for that method
then call invoke on the form. Something like:

SomeForm someFrm = new SomeForm();
....

if( someFrm.InvokeRequired )
{
someFrm.Invoke( new DoSomethingDelegate(
SomeForm.DoSomething()), new objet[]{
param1, param2 } );
}
else
{
someFrm.DoSomething(param1, param2);
}

Please see these two articles for some more
information:

Safe, Simple Multithread in Windows Forms
http://tinyurl.com/29sd [MSDN]

Second Look at Multithreading in Windows Forms
http://tinyurl.com/k480 [MSDN]

-c
Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1285
by: Eric Williams | last post by:
Hello all, I'm working on a little application using PyQt. The main window is just a dialog with 2 progress bars and a few labels. In its original form, the dialog started, then ran a function...
1
1397
by: Joshua Russell | last post by:
Firstly my main method is like this: static void Main(string args) { // New Form Thread FormHandler myFormHandler = new FormHandler(); ThreadStart myThreadStart = new...
5
2182
by: Claire | last post by:
My progress window is created by a secondary thread and then updated by it while a file is uploaded. There's an avi animation control on there that should show the move file avi. Plus a progress...
14
4073
by: | last post by:
Hi All, I am little confused here, hope you can help me. While processing WM_POWERBROADCAST (wParam=PBT_APMQUERYSUSPEND), I MUST to do some lengthy operation(30 sec) before system Suspends or...
1
1140
by: TGriffith | last post by:
I have a function and OPEN.WINDOW event that occurs when the suer presses a button. I want to set a value in the New Window and upate a value on the parent form. Is this a javascript solution only?...
14
2912
by: el_sid | last post by:
Our developers have experienced a problem with updating Web References in Visual Studio.NET 2003. Normally, when a web service class (.asmx) is created, updating the Web Reference will...
2
2065
by: John J. Hughes II | last post by:
I have a form with a socket which is handled by the beginReceive function. When the data is received it is in turn returned to the window for display. I have done this several times before and the...
2
1300
by: binarybrain | last post by:
I have encountered a problem that I am having trouble solving. I have one main UI. From this UI you can bring up a new non-modal Windows form that displays some other data. However, each time a...
0
1550
by: Code Monkey | last post by:
Suppose I have a windows form (.exe) that has a load of labels and text boxes on it. I enter a number into one of the text boxes and hit the search button. This then launches another thread,...
0
7203
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
7089
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
7339
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...
1
6995
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...
1
5017
isladogs
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...
0
4678
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...
0
3168
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...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
389
bsmnconsultancy
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...

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.