Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / October 2004

Tip: Looking for answers? Try searching our database.

Updating the UI from a Secondary Thread

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BG - 25 Oct 2004 19:06 GMT
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.

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(object sender, System.EventArgs e)

{

     // Create and show the splash screen

     SplashScreen frmSS = new SplashScreen();

     frmSS.Show();

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

     BackgroundProcess bp = new BackgroundProcess();

     bp.StartingDirectory = @"C:\";

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

     System.Threading.Thread activeThread = new System.Threading.Thread(new
System.Threading.ThreadStart(bp.StartProcess));

     activeThread.Start();

     while (activeThread.IsAlive)

     {

           Application.DoEvents();

     }

     // 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.
Carl Daniel [VC++ MVP] - 25 Oct 2004 21:42 GMT
> 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.public.dotnet.languages.csharp

-cd
BG - 25 Oct 2004 22:12 GMT
Thanks, I'll do that.

> > We're having trouble writing the code to update a UI control
> > (label.Text) from a secondary thread.  We're using C# with Windows
[quoted text clipped - 3 lines]
>
> -cd

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.