473,574 Members | 3,070 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 3222
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
4637
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
2541
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
14118
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). ...
3
3041
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...
3
4175
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...
14
6372
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...
0
2464
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...
7
1731
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 ...
4
2570
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...
0
7764
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...
0
8273
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6514
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...
1
5658
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...
0
5336
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...
0
3775
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...
0
3794
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1375
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.