Click here to Skip to main content
15,891,372 members
Articles / Programming Languages / C#

How to Properly Handle Cross-thread Events and Update a Label with BeginInvoke and BackgroundWorker

Rate me:
Please Sign up or sign in to vote.
4.79/5 (19 votes)
8 Feb 2008LGPL33 min read 140.1K   2.6K   55  
This article explains how to update a Label using cross-thread event handling, delegates, BeginInvoke and BackgroundWorker.
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle ( "EventHandlingExample" )]
[assembly: AssemblyDescription ( "" )]
[assembly: AssemblyConfiguration ( "" )]
[assembly: AssemblyCompany ( "World Bombers" )]
[assembly: AssemblyProduct ( "EventHandlingExample" )]
[assembly: AssemblyCopyright ( "Copyright © World Bombers 2008" )]
[assembly: AssemblyTrademark ( "" )]
[assembly: AssemblyCulture ( "" )]

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible ( false )]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid ( "f9525da3-261f-4d2e-b33d-a9d6895aa1e5" )]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion ( "1.0.0.0" )]
[assembly: AssemblyFileVersion ( "1.0.0.0" )]

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Founder Dice Informatica
Brazil Brazil
Guilherme is bachelor in Computer Science, graduated on 2007 at PUC-RS/Brazil, and post-graduated (latu sensu) on IT Project Management at PUC-RS/Brazil on 2009.

Currently working on his own ISV company, he develops custom software solutions for other companies.

His carreer interests are:

- Software Engineering;
- Computer Graphics;
- Game Development;
- Multi-agent Systems;
- Multi-core programming;

He works with C# .net since version 1.1;

Comments and Discussions