I need progress bar in windows form application but my process is not length specific so I can’t maximum value to progressbar.
I must increment progress bar value using LongProcess class Run method elapsed time.
void start_click()
{
button1.Enabled=false;
Task.Factory.StartNew(()=>{
Parallel.Foreach(files,f=>{
LongProcess process =new LongProcess(); // Long-running process (is not my control)
process.Run(f);
//progressBarValueIncrement();
});
}).ContinueWith(t=>{
// completed
BeginInvoke(new Action(() => button1.Enabled=true));
});
}
How can i implement this?
you could increment the progress bar with some percentage of the remaining unfilled value. This would mean that the progress bar never filled up though and would get fuller more and more slowly.
So in the first increment you fill the progress bar 50%, then next increment you fill 50% of the remainder, so 25% for a total of 75%, then 50% of remaining 25%, total 87.5% etc etc.
you may want to stage it so that the %age you used was based on how full the progress bar was, so start with 5% at the beginning so it doesn’t fill up too quickly at the start, then move to higher percentages so you can see the bar moving still near the end…
If you don’t know how long something is going to take though, is a progress bar appropriate? Maybe you would be better with something that showed progress was happening, but not how much has been completed…