By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,773 Members | 1,779 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,773 IT Pros & Developers. It's quick & easy.

Backgroundworker Control

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.