Need help on how to use .Net's Backgroundworker thread for the following purpose to increase UI responsiveness and performance in my .Net winforms application. When user clicks "Calculate" button in UI form,I'm doing this:
1.Get a list of categories C from database[this is typically around 10]
2.For each category C, do the following:
a.Call a third-party library, do some processing and calculate category price.
b.Get a list of products[This is typically around 800].
c.For each product, calculate its price using its category price from above.
d.Update this price of each product back in the database using a stored proc.
3.Update the progress back[or report any error message] to a form in UI.
FYI,I want to use Backgroundworker for steps #c and #d above.
I tried using Backgroundworker in my method.I put calls to InitializeBackgroundworker() and RunWorkerAsync() in the outermost loop[ie. step 2].But looks like, Backgroundworker is getting invoked only for the first category.What am I missing here?
So my question is, where do I make a call to InitializeBackgroundworker() and RunWorkerAsync()? And how do I make sure these 2 methods get called for each category?
Thanks for reading.
Loading
Sam HobbsPosted Sep 1, 2010, 6:07 PM
Are you sure it is possible to call RunWorkerAsync more than once? I would read the documentation to be sure. Are you sure that the main thread and the worker thread are synchronized so that the main thread does not call RunWorkerAsync while it is busy? I assume that calling RunWorkerAsync while it was busy would not work. Are you using try/catch to catch errors? If not, then please do. Always ensure that there are no unprocessed errors before asking others for help.
Actually I think that RunWorkerAsync is an event that executes the thread, so it makes sense to me that when you call RunWorkerAsync while the thread is busy, RunWorkerAsync determines that the thread is already busy and does nothing more.
Chris RileyPosted Sep 1, 2010, 12:00 PM
your explanation vaguely describes what you are looking to do, but left me sleeping on my keyboard
your solution :: http://lmgtfy.com/?q=using+.net+background+worker