Click here to Skip to main content
15,911,890 members
Home / Discussions / C#
   

C#

 
GeneralRe: Kernelbase error on Server 2008 Pin
Paladin200030-Jul-10 6:04
Paladin200030-Jul-10 6:04 
QuestionDoes anyone encountered problems with using of multiple TCP channels in .NET remoting app? [modified] Pin
Slava_K13-Apr-10 8:28
Slava_K13-Apr-10 8:28 
AnswerRe: Does anyone encountered problems with using of multiple TCP channels in .NET remoting app? Pin
thugthug15-Apr-10 5:17
thugthug15-Apr-10 5:17 
QuestionNPlot - how do I not show weekend dates Pin
boreland13-Apr-10 7:36
boreland13-Apr-10 7:36 
QuestionBackground Worker with Multiple Progress Bars Pin
eddieangel13-Apr-10 7:07
eddieangel13-Apr-10 7:07 
AnswerRe: Background Worker with Multiple Progress Bars Pin
Luc Pattyn13-Apr-10 7:23
sitebuilderLuc Pattyn13-Apr-10 7:23 
GeneralRe: Background Worker with Multiple Progress Bars Pin
eddieangel13-Apr-10 8:47
eddieangel13-Apr-10 8:47 
GeneralRe: Background Worker with Multiple Progress Bars Pin
Luc Pattyn13-Apr-10 9:55
sitebuilderLuc Pattyn13-Apr-10 9:55 
If you only have two progress bars, one overall, one for current file, all you need to pass is two percentages. So a simple struct, or an int[2] array would do. However, I would be inclined to make it even simpler:
foreach (string filename in filenames) {
    // signal new file
    ReportProgress(101, filename);
    // now do file operation and report progress
    ... some kind of loop {
        ...
        ReportProgress(percentage, filename);
    }
    // signal end of file
    ReportProgress(102, filename);
}


and let the ProgressChanged event do the math:
long totalDone;
long overallTotal;
Directory<string filename, long filesize> namesToSizes;

void ProgressChanged(object sender, ProgressChangedEventArgs e) {
    int p=e.ProgressPercentage;
    string filename=e.UserState;
    long filesize=namesToSizes[filename];
    if (p==101) {
        labelIndividual.Text="now dealing with file "+filename;
    } else if (p==102) {
        totalDone+=filesize;
    } else {
        ProgressBarIndividual.Value=p;
        ProgressBarTotal.Value=(totalDone+filesize*p/100)*100/overallTotal;
    }
}


You have to set up overallTotal and namesToSizes before entering the loop.

Note: While the documentation calls the first parameter "percentProgress", it is not limited to the range [0, 100] so I used two values outside that range to request special actions.

Smile | :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]

Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.


modified on Tuesday, April 13, 2010 8:28 PM

GeneralRe: Background Worker with Multiple Progress Bars Pin
eddieangel13-Apr-10 13:46
eddieangel13-Apr-10 13:46 
QuestionPassing different variable types Pin
mprice21413-Apr-10 4:51
mprice21413-Apr-10 4:51 
AnswerRe: Passing different variable types Pin
Luc Pattyn13-Apr-10 5:54
sitebuilderLuc Pattyn13-Apr-10 5:54 
GeneralRe: Passing different variable types Pin
dan!sh 13-Apr-10 6:12
professional dan!sh 13-Apr-10 6:12 
GeneralRe: Passing different variable types Pin
Luc Pattyn13-Apr-10 6:28
sitebuilderLuc Pattyn13-Apr-10 6:28 
GeneralRe: Passing different variable types Pin
dan!sh 13-Apr-10 6:46
professional dan!sh 13-Apr-10 6:46 
GeneralRe: Passing different variable types Pin
Luc Pattyn13-Apr-10 6:47
sitebuilderLuc Pattyn13-Apr-10 6:47 
GeneralRe: Passing different variable types Pin
DaveyM6913-Apr-10 8:25
professionalDaveyM6913-Apr-10 8:25 
GeneralRe: Passing different variable types Pin
mprice21413-Apr-10 6:30
mprice21413-Apr-10 6:30 
GeneralRe: Passing different variable types Pin
Luc Pattyn13-Apr-10 6:46
sitebuilderLuc Pattyn13-Apr-10 6:46 
GeneralRe: Passing different variable types Pin
mprice21413-Apr-10 7:56
mprice21413-Apr-10 7:56 
GeneralRe: Passing different variable types Pin
Luc Pattyn13-Apr-10 8:02
sitebuilderLuc Pattyn13-Apr-10 8:02 
AnswerRe: Passing different variable types Pin
kevinnicol13-Apr-10 6:19
kevinnicol13-Apr-10 6:19 
GeneralRe: Passing different variable types Pin
mprice21413-Apr-10 6:32
mprice21413-Apr-10 6:32 
QuestionHow to Save the Excel file with some file format [modified] [Solved] Pin
yu-jian13-Apr-10 4:37
yu-jian13-Apr-10 4:37 
AnswerRe: How to Save the Excel file with some file format Pin
Dan Mos13-Apr-10 5:13
Dan Mos13-Apr-10 5:13 
Questiondatagrid checkbox Pin
Morgs Morgan13-Apr-10 4:26
Morgs Morgan13-Apr-10 4:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.