Click here to Skip to main content
15,894,646 members
Home / Discussions / C#
   

C#

 
QuestionCannot focus treeNode in a panel Pin
Kim06182-Sep-08 4:14
Kim06182-Sep-08 4:14 
AnswerRe: Cannot focus treeNode in a panel Pin
leppie2-Sep-08 4:23
leppie2-Sep-08 4:23 
GeneralRe: Cannot focus treeNode in a panel Pin
Kim06182-Sep-08 16:06
Kim06182-Sep-08 16:06 
QuestionProgressBar in multi-threaded application Pin
Lutosław2-Sep-08 4:03
Lutosław2-Sep-08 4:03 
AnswerRe: ProgressBar in multi-threaded application Pin
TheFM2342-Sep-08 4:18
TheFM2342-Sep-08 4:18 
AnswerRe: ProgressBar in multi-threaded application Pin
leppie2-Sep-08 4:24
leppie2-Sep-08 4:24 
GeneralRe: ProgressBar in multi-threaded application Pin
Lutosław2-Sep-08 6:12
Lutosław2-Sep-08 6:12 
AnswerRe: ProgressBar in multi-threaded application Pin
#realJSOP2-Sep-08 5:05
mve#realJSOP2-Sep-08 5:05 
You're making it harder than it has to be.

Use a BackgroundWorker object to perform the calculation, and call the UpdateProgress method at the desired interval.

private BackgroundWorker myWorker = BackgroundWorker();

//--------------------------------------------------------------------------------
/// <summary>
/// Initializes the background worker thread.
/// </summary>
private void InitEncryptWorker()
{
    myWorker.WorkerReportsProgress	= true;
    myWorker.WorkerSupportsCancellation = true;
    myWorker.DoWork                    += new System.ComponentModel.DoWorkEventHandler(myWorker_DoWork);
    myWorker.RunWorkerCompleted        += new System.ComponentModel.RunWorkerCompletedEventHandler(myWorker_RunWorkerCompleted);
    myWorker.ProgressChanged           += new System.ComponentModel.ProgressChangedEventHandler(myWorker_ProgressChanged);
}

//--------------------------------------------------------------------------------
public void myWorker_DoWork(Object sender, DoWorkEventArgs e)
{
    BackgroundWorker thisWorker = sender as BackgroundWorker;
    
    int progress = 0;
    for (int i = 0; i < 1000; i++)
    {
        if (!thisWork.CancellationPending)
        {
            // do some work here

            // and then report progress
            thisWorker.ReportProgress(progress);
        }
    }
}

//--------------------------------------------------------------------------------
private void myWorker_ProgressChanged(object sender,ProgressChangedEventArgs e)
{
    if (e.ProgressPercentage != this.progressBar.Value)
    {
        this.progressBar.Value = e.ProgressPercentage;
    }
}


//--------------------------------------------------------------------------------
private void myWorker_RunWorkerCompleted(object sender,RunWorkerCompletedEventArgs e)
{
}



"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001


GeneralRe: ProgressBar in multi-threaded application Pin
Lutosław2-Sep-08 6:09
Lutosław2-Sep-08 6:09 
GeneralRe: ProgressBar in multi-threaded application Pin
#realJSOP2-Sep-08 7:43
mve#realJSOP2-Sep-08 7:43 
GeneralRe: ProgressBar in multi-threaded application Pin
Mark Salsbery2-Sep-08 7:56
Mark Salsbery2-Sep-08 7:56 
GeneralRe: ProgressBar in multi-threaded application Pin
Lutosław2-Sep-08 9:09
Lutosław2-Sep-08 9:09 
GeneralRe: ProgressBar in multi-threaded application Pin
#realJSOP2-Sep-08 9:58
mve#realJSOP2-Sep-08 9:58 
AnswerRe: ProgressBar in multi-threaded application Pin
Daniel Grunwald2-Sep-08 6:22
Daniel Grunwald2-Sep-08 6:22 
GeneralRe: ProgressBar in multi-threaded application Pin
Lutosław2-Sep-08 6:29
Lutosław2-Sep-08 6:29 
GeneralRe: ProgressBar in multi-threaded application Pin
Lutosław2-Sep-08 9:33
Lutosław2-Sep-08 9:33 
GeneralRe: ProgressBar in multi-threaded application Pin
Daniel Grunwald2-Sep-08 9:38
Daniel Grunwald2-Sep-08 9:38 
QuestionID Pin
ellllllllie2-Sep-08 3:07
ellllllllie2-Sep-08 3:07 
AnswerRe: ID Pin
Manas Bhardwaj2-Sep-08 3:36
professionalManas Bhardwaj2-Sep-08 3:36 
GeneralRe: ID Pin
leppie2-Sep-08 3:45
leppie2-Sep-08 3:45 
AnswerRe: ID Pin
leppie2-Sep-08 3:43
leppie2-Sep-08 3:43 
GeneralRe: ID Pin
Anthony Mushrow2-Sep-08 6:35
professionalAnthony Mushrow2-Sep-08 6:35 
AnswerRe: ID Pin
Pete O'Hanlon2-Sep-08 4:22
mvePete O'Hanlon2-Sep-08 4:22 
AnswerRe: ID Pin
Pete O'Hanlon2-Sep-08 8:09
mvePete O'Hanlon2-Sep-08 8:09 
QuestionC# Classes Pin
Stephen Lintott2-Sep-08 3:07
Stephen Lintott2-Sep-08 3:07 

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.