473,756 Members | 9,160 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BackGroundWorke r with Datalayer class. Reporting Progress.

Bob
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 progress event.

So I added a bw to the form. The Dowork Calls a method which instantiates a
DT and calls its Dataprocessing method.

I can't see how to bubble progress up from the DT event to the Form.

If I am on the right track here , the bw will handle the DT event (How?) ,
then it will raise its own ProgressChanged Event. The UI handles the bw
ProgressChanged Event and updates the progress bar.
Thanks in Advance.
Bob
Nov 15 '06 #1
1 3231
Hi Bob,

1. You must set WorkerReportsPr ogress to true on the BackgroundWorke r object.

2. Register an event handler with the ProgressChanged event on the
BackgroundWorke r. The handler will be invoked on the UI thread, so you can
update a ProgressBar control or whatever you'd like.

3. In the DoWork event handler, register an event handler for the progress
changed event of the DT object that is created.

4. In the event handler for the DT progress change event, call the
ReportProgress method on the BackgroundWorke r

Anonymous methods can make this process much easier for you if you don't have
a global variable declared for the BackgroundWorke r or if you create a new
BackgroundWorke r each time the process must run:

BackgroundWorke r worker = new BackgroundWorke r();
worker.WorkerRe portsProgress = true;

// ProgressBar control
progress.Value = 0;

worker.Progress Changed += delegate(object sender1, ProgressChanged EventArgs
e1)
{
// update the progress bar
progress.Value = e1.ProgressPerc entage;
};

worker.DoWork += delegate(object sender1, DoWorkEventArgs e1)
{
// here you would create your DT object
// here you would register an event handler - another anonymous
// method could be used so you have access to the "worker"
// variable in the event handler

// as an example, I'll just update the progress directly:

for (int i = 1; i <= 10; i++)
{
System.Threadin g.Thread.Sleep( 100);

worker.ReportPr ogress(i * 10);
}

worker.ReportPr ogress(100);
};

worker.RunWorke rAsync();

--
Dave Sexton

"Bob" <bo*@nowhere.co mwrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
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 progress event.

So I added a bw to the form. The Dowork Calls a method which instantiates a
DT and calls its Dataprocessing method.

I can't see how to bubble progress up from the DT event to the Form.

If I am on the right track here , the bw will handle the DT event (How?) ,
then it will raise its own ProgressChanged Event. The UI handles the bw
ProgressChanged Event and updates the progress bar.
Thanks in Advance.
Bob


Nov 17 '06 #2

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

Similar topics

2
4648
by: WB | last post by:
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/library/system.componentmodel.backgroundworker.aspx
4
2555
by: DHarry | last post by:
Can anybody tell me, whats the main difference between a BackgroundWorker and a Thread? What are the advantages/disadvanteges? When use a BackgroundWorker, when a Thread?
5
14134
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 my FileIO class) I've established Public Event in my core logic classes along with RaiseEvents (that will updated a progress bar on the UI side). This all works great when I'm NOT using Threading (BackgroundWorker), however, as soon as I...
3
3057
by: Hardy Wang | last post by:
Hi all, I am migrating a Windows Form application from .Net 1.1 to 2.0. I try to use BackgroundWorker object to handle a very lengthy process. I have a separated class to handle some very complex logic. In .Net 1.1, I create some events inside this class to notify WinForm the status of process: obj.OneFileStarted += new OneFileStartedEventHandler(obj_OneFileStarted); obj.OneFileFinished += new...
3
4186
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, it reads in the bytes and finds the header and footer and pulls packets out of the data stream. Nice, easy stuff. It then stuffs the packet into into a class I made up to pull the data out through the ProgressChanged event. The class is pretty...
14
6394
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 the do work method, it stops for a long while and then executes the first line of the method and the doesn't do anything else. What am i doing wrong?
0
2479
by: Chris | last post by:
I would like to be able to pass the BackgroundWorker object and DoWork Event Args to a second function (third function?) and be able to still report the progress. I'm getting the following exception when trying to access BackgroundWorker.CancellationPending or e.Cancel An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll Additional information: Exception has been thrown by the target of...
7
1751
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 Trace that prints always what bgw has unzipped and what ProgressChanged received: 1. bgw: HelpFilelistgzip 2. ProgressChanged: HelpFilelistgzip OK!
4
2583
by: Sin Jeong-hun | last post by:
This is what I've always been wondered. Suppose I've created a class named Agent, and the Agent does some lengthy job. Of course I don't want to block the main window, so the Agent does the job in a separate thread. If the job is progressed it fires an event, and the main window handled the event by changing the value of a progress bar. The problem is that this event is fired in another thread so when the handler in the main window tries...
0
9482
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
9292
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,...
1
9878
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
9728
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8733
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...
0
6551
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5322
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3392
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2694
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.