473,323 Members | 1,589 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,323 software developers and data experts.

Backgroundworker Control

Hi --

I have a C# application that basically has a button that executes a SQL
Reader to loop thru a rather large resul set. Thru each interation of the
reader object, I check to see if a file exists on the server. If it does, I
update a textbox (multiline) with the missing file, update a status bar
label, and a progressbar. Since this process is kind of lengthy, every 400
rows, I do a DoEvents() and TextBox.Refersh() to refresh the form and
control... so I can see the updated info in the textbox.

This seems to work fine and is OK, but I thought that using the new
Backgroundworker control would make my UI more responsive and I could likely
remove the DoEvents and junk.

Anyway, from what I've seen thus far... it looks like the DoEvent function
of the backgroundworker control does not allow me to interact with any UI
controls. I see that I can report the progress back to my ProgressEvent,
but that appears to be all.

What is the best practice for handling this sort of scanerio?

Surely I can't be the only one that has wanted to run a query in the
background, update some controls, and finally release control back to the
main UI?????

Mar 23 '06 #1
2 9249
I personally don't find the background worker all that helpful as it is
easier, IMO, to do it yourself. Try this:
http://channel9.msdn.com/ShowPost.aspx?PostID=171594

--
William Stacey [MVP]

"dm1608" <dm****@spam.net> wrote in message
news:e0**************@tk2msftngp13.phx.gbl...
| Hi --
|
| I have a C# application that basically has a button that executes a SQL
| Reader to loop thru a rather large resul set. Thru each interation of the
| reader object, I check to see if a file exists on the server. If it does,
I
| update a textbox (multiline) with the missing file, update a status bar
| label, and a progressbar. Since this process is kind of lengthy, every
400
| rows, I do a DoEvents() and TextBox.Refersh() to refresh the form and
| control... so I can see the updated info in the textbox.
|
| This seems to work fine and is OK, but I thought that using the new
| Backgroundworker control would make my UI more responsive and I could
likely
| remove the DoEvents and junk.
|
| Anyway, from what I've seen thus far... it looks like the DoEvent function
| of the backgroundworker control does not allow me to interact with any UI
| controls. I see that I can report the progress back to my ProgressEvent,
| but that appears to be all.
|
| What is the best practice for handling this sort of scanerio?
|
| Surely I can't be the only one that has wanted to run a query in the
| background, update some controls, and finally release control back to the
| main UI?????
|
|
|
Mar 23 '06 #2
If the BackgroundWorker had access to the Controls, it would have the same
problem as any other separate thread in a Windows Form. That is, since the
work of the BackgroundWorker is conducted on a separate thread from the main
form thread, accessing Form controls is a dangerous threading risk to take.
That is why the BackgroundWorker raises an event that the Form thread itself
can respond to.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"dm1608" <dm****@spam.net> wrote in message
news:e0**************@tk2msftngp13.phx.gbl...
Hi --

I have a C# application that basically has a button that executes a SQL
Reader to loop thru a rather large resul set. Thru each interation of the
reader object, I check to see if a file exists on the server. If it does,
I update a textbox (multiline) with the missing file, update a status bar
label, and a progressbar. Since this process is kind of lengthy, every
400 rows, I do a DoEvents() and TextBox.Refersh() to refresh the form and
control... so I can see the updated info in the textbox.

This seems to work fine and is OK, but I thought that using the new
Backgroundworker control would make my UI more responsive and I could
likely remove the DoEvents and junk.

Anyway, from what I've seen thus far... it looks like the DoEvent function
of the backgroundworker control does not allow me to interact with any UI
controls. I see that I can report the progress back to my ProgressEvent,
but that appears to be all.

What is the best practice for handling this sort of scanerio?

Surely I can't be the only one that has wanted to run a query in the
background, update some controls, and finally release control back to the
main UI?????

Mar 23 '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...
3
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...
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...
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...
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...
1
by: nondos | last post by:
Is it possible to suspend BackGroundWorker Control like it's possible in thread? Thanks
4
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...
1
by: schnandr | last post by:
Hi, I have a user control which contains ListView. I copy all ListViewItems into a separate List<ListViewItemcalled unfilteredItems. I am using a BackgroundWorker to filter the ListView. When...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.