Connecting Tech Pros Worldwide Help | Site Map

Backgroundworker for recursive loop

Newbie
 
Join Date: Jan 2009
Posts: 3
#1: Jun 27 '09
Hi,

I am new to windows application. Can anyone give me the answer on my issue? The issue is updating the progressbar of bgworker from recursive loop. The recursive loop is using to find the directory that I want to delete. Basically, the loop is working great also the bgworker has no problem I remove the update progress function. The error is exceeding the value of progressbar. Is there anyway to update the progressbar on the fly of directory search?

Thanks
Sithu
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Jun 29 '09

re: Backgroundworker for recursive loop


What do you mean by "The error is exceeding the value of progressbar"?
Expert
 
Join Date: Jan 2008
Location: York
Posts: 179
#3: Jun 29 '09

re: Backgroundworker for recursive loop


Quote:

Originally Posted by r035198x View Post

What do you mean by "The error is exceeding the value of progressbar"?

He most likely means he is trying to set the ProgressBar.Value to a value larger than ProgressBar.MaxValue.

Firstly you need to check that you have initialized the MaxValue property with a sensible value, then you need to ensure that your logic isn't setting a silly value, 101% for example. If you want to be extra safe then doing a check before setting it

if(value > ProgressBar.MaxValue) { value = ProgressBar.Value;}
Newbie
 
Join Date: Jan 2009
Posts: 3
#4: Jun 29 '09

re: Backgroundworker for recursive loop


Hi,

Thanks for your answers. I would say straightly though, it is not the answer I expected. I am wondering how to set the max value of progresbar dynamically(the recursive loop could find unlimited directories in runtime). Is there any workaround?

Thanks
SiThu
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#5: Jun 30 '09

re: Backgroundworker for recursive loop


Well first make sure to be explicit on what you mean in your questions. As you can see there are mind readers with shiny crystal balls here who can read in between the lines to understand what you mean but it's best to be explicit so that mere mortals like me can also follow the conversation.
So you don't know how many files are going to be searched but want to show progress in terms of percentage of work done so far? Well that's just impossible. To express a percentage to need what the total is supposed to be. Better throw away that idea altogether and just show the number of files searched so far like most file searchers do.
Newbie
 
Join Date: Jan 2009
Posts: 3
#6: Jun 30 '09

re: Backgroundworker for recursive loop


Yeah, you are right. Thank you
Reply


Similar C# / C Sharp bytes