473,698 Members | 2,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updating the UI from a Secondary Thread

BG
We're having trouble writing the code to update a UI control (label.Text)
from a secondary thread. We're using C# with Windows Forms.

We have a main form named MainForm, a splash screen form named SplashScreen,
and a C# class library named BackgroundProce ss.

On application start, we simply want to show the splash screen form, kick
off the background processing on a separate thread, and, at different points
in the background processing, update a label on the splash screen to inform
the user of what the application is doing. When the processing is done, the
splash screen form goes away and the main form appears.

In the main form's form load event we have:

private void MainForm_Load(o bject sender, System.EventArg s e)

{

// Create and show the splash screen

SplashScreen frmSS = new SplashScreen();

frmSS.Show();

// Create the object for background processing and set an initial
property

BackgroundProce ss bp = new BackgroundProce ss();

bp.StartingDire ctory = @"C:\";

// Create a new thread for the background processing and start it

System.Threadin g.Thread activeThread = new System.Threadin g.Thread(new
System.Threadin g.ThreadStart(b p.StartProcess) );

activeThread.St art();

while (activeThread.I sAlive)

{

Application.DoE vents();

}

// Clean up

activeThread = null;

bp = null;

frmSS.Close();

frmSS = null;

}

This code works, and the code in our class library (i.e., the background
processing code) works, but we still can't get the splash screen's label to
update.

We've trying using delegates/events, etc. and have not been successful in
getting the label updated from the secondary thread that's doing all the
"behind-the-scenes" processing.

Any suggestions?

Thanks.


Nov 17 '05 #1
2 1189
BG wrote:
We're having trouble writing the code to update a UI control
(label.Text) from a secondary thread. We're using C# with Windows
Forms.

You probably want to post this in microsoft.publi c.dotnet.langua ges.csharp

-cd
Nov 17 '05 #2
BG
Thanks, I'll do that.
"Carl Daniel [VC++ MVP]" <cp************ *************** **@mvps.org.nos pam>
wrote in message news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
BG wrote:
We're having trouble writing the code to update a UI control
(label.Text) from a secondary thread. We're using C# with Windows
Forms.

You probably want to post this in microsoft.publi c.dotnet.langua ges.csharp

-cd

Nov 17 '05 #3

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

Similar topics

2
4912
by: Hal Vaughan | last post by:
First, I am aware of both SwingUtilities.invokeLater(), and of using Thread to create a new thread.  These are part of the problem. I want to have something running in the background, while the GUI is updating.  I've done that before without a problem, however, now, I need to pass variables to the separate Thread or Runnable that I'm using.  I'm using something like this: //Other code setting things up and updating GUI //Variables...
5
2190
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 bar. Im having problems as the screen isn't being redrawn properly. If I call DoEvents each time then it works ok. I want to dump DoEvents to prevent problems. I'm calling the following from the progress property set function. InvokeRequired...
2
11785
by: BG | last post by:
We're having trouble writing the code to update a UI control (label.Text) from a secondary thread. We're using C# with Windows Forms. We have a main form named MainForm, a splash screen form named SplashScreen, and a C# class library named BackgroundProcess.
3
3768
by: Dale Lundgren | last post by:
I have a c# class library that launches a Win Form in a secondary thread. From the Form (now running in the secondary thread) I need to be able to start a method that is defined in the class and have it run in the main thread. I have read many examples and tried numerous approaches based on delegates all of which will launch the method, but never in the main thread, always in the secondary thread. Is what I'm trying to accomplish...
14
2948
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 utilise the disco file to update the Corresponding proxy file and reflect the changes made to the web service. However, the results of doing this with out params is that the results seem
5
12520
by: Mark R. Dawson | last post by:
Hi all, I may be missing something with how databinding works but I have bound a datasource to a control and everything is great, the control updates to reflect the state of my datasource when I update the datasource - awesome, but I have an issue with updating from a different thread. Here is my datasource, a person class that raises the PropertyChanged event: class Person : INotifyPropertyChanged {
3
7303
by: Mike Binks | last post by:
I wish to make sure all unhandled exceptions (UE) are handled by a central handler. For primary thread UEs, this may be done by string exceptionText; AppDomain.CurrentDomain.UnhandledException += delegate(object sender, UnhandledExceptionEventArgs e) { exceptionText = e.ExceptionObject.ToString();
5
3448
by: Ale | last post by:
Hi to everyone, i've a problem, i'm trying to edit a control from a secondary thread (i'm using the backgroundworker) the problem is that i can't edit something in that way.. and i get back a Cross-Thread exception... Some one can help me? any workaround? Thank you in advance.
2
1315
Logan1337
by: Logan1337 | last post by:
Hi. This is an odd question because I'm not sure if it's a bug or if this is how it is supposed to behave, however what is happening is I have a main window of my application that is passed to Application.Run, and then I have a secondary window (a welcome screen) which is created afterwards and shown on the same thread. However, the problem is that when the first window shows a dialog window, which is supposed to be tied to it, the secondary...
8
1985
by: Daniele Piccinini | last post by:
Hi all, In my vc++ 2005 dialog based application i need to use a comunication activex component in a secondary thread: CFINSAxEFS* pNewAx = new CFINSAxEFS(); if ( !pNewAx->Create( NULL, NULL, CRect( 0,0,0,0), pParent, pNode->m_nFinsID) )
0
8683
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, 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...
0
8610
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
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, 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...
1
8902
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,...
0
7740
agi2029
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...
1
6528
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 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...
0
4372
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...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2007
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 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...

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.