473,770 Members | 1,823 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 3233
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
4649
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
2556
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
4187
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
6396
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
2480
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
1752
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
2584
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
9617
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
9453
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,...
0
10099
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9904
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...
1
7451
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
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
5481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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
3
2849
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.