473,385 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

BackgroundWorker.ProgressChanged Event

WB
Hi,

My Windows application has a time-consuming operation which I'd like to run
on a separate thread so that the UI can remain responsive.

I'm thinking of using the BackgroundWorker class and have referred to a
relevant MSDN article at:

http://msdn2.microsoft.com/en-us/lib...undworker.aspx

However, I notice that "ProgressChangedEventArgs" of the
"backgroundWorker1_ProgressChanged" event handler only has a parameter
"ProgressPercentage". When I give progress updates I'd like to give more
information by, for example, displaying text in a text box (eg. "Found 3
pending customer orders"), instead of simply incrementing a progress bar. Now
how can I accomplish this?

ywb.
Apr 27 '06 #1
2 4628
WB <WB@discussions.microsoft.com> wrote:
My Windows application has a time-consuming operation which I'd like to run
on a separate thread so that the UI can remain responsive.
[snip]
When I give progress updates I'd like to give more
information by, for example, displaying text in a text box (eg. "Found 3
pending customer orders"), instead of simply incrementing a progress bar. Now
how can I accomplish this?


You'll have to update the textbox on the main UI thread. You can marshal
the action over to the UI thread with ISynchronizeInvoke.Invoke /
Control.Invoke. The easiest way to send all the code across is via an
anonymous delegate. For example:

---8<---
using System;
using System.Windows.Forms;
using System.Threading;

class App
{
delegate void Method();

static void Main()
{
Form f = new Form();
f.Text = "Form";

ThreadPool.QueueUserWorkItem(delegate
{
Thread.Sleep(2000);
f.Invoke((Method) delegate
{
f.Text = "Changed!";
});
});

Application.Run(f);
}
}
--->8---

-- Barry
Apr 27 '06 #2
On Thu, 27 Apr 2006 13:53:02 -0700, WB wrote:
However, I notice that "ProgressChangedEventArgs" of the
"backgroundWorker1_ProgressChanged" event handler only has a parameter
"ProgressPercentage". When I give progress updates I'd like to give more
information by, for example, displaying text in a text box (eg. "Found 3
pending customer orders"), instead of simply incrementing a progress bar. Now
how can I accomplish this?


ProgressChangedEventArgs has another property: UserState. When calling the
ReportProgress method, you can use the userState parameter to pass a custom
object that contains the information that you want to display to the user.
In the ProgressChanged event handler, you can then cast the UserState to
the type of your custom object and retrieve the info.
Apr 28 '06 #3

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

Similar topics

8
by: Pieter | last post by:
Hi, I'm having some weird problem using the BackGroundWorker in an Outlook (2003) Add-In, with VB.NET 2005: I'm using the BackGroundWorker to get the info of some mailitems, and after each item...
5
by: Rob R. Ainscough | last post by:
I'm using a BackgroundWorker to perform a file download from an ftp site. Per good code design practices where I separate my UI code from my core logic code (in this case my Download file method in...
1
by: Bob | last post by:
Hi, I am having trouble seeing how this bolts together. The UI starts a process which involves a long running database update. All Database activity is handled by a class called DT. DT has a...
3
by: ray.ackley | last post by:
Hello all, I have an app that uses a BackgroundWorker() object to read USB data that is being fed in serially (FT245R chip, www.ftdichip.com). It looks just like a serial data stream. Anyhow,...
14
by: =?Utf-8?B?SXNobWFlbA==?= | last post by:
Hi, I have a form with a progress bar on it and wanted to use the BackgroundWorker to be able to update the progress. I looked at examples, run some of them, but in debug, when the code gets to...
7
by: =?Utf-8?B?SGVucnk5OQ==?= | last post by:
What happens here? The backgroundworker (bgw) unzips RTF-Helpfiles (up to 1 MB in size). The ProgressChanged-Event gets the unzipped files (to display them in a RichtTextBox) It follows the...
9
by: RvGrah | last post by:
I'm completely new to using background threading, though I have downloaded and run through several samples and understood how they worked. My question is: I have an app whose primary form...
3
by: vulpes | last post by:
How do I implement the "incremental results" with a BackgroundWorker? Many pages, http://msdn2.microsoft.com/en-us/library/wewwczdw.aspx for example, tell that I should subclass the...
4
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hi misters, I have winForm that needs update Panel (add controls to Panel of SplitContainer dynamically). I have a Backgroundworker, and DoWork event I want to add controls but I get this...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
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...

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.