locked
Windows Forms Progress/Status Bar RRS feed

  • Question

  • Hi,

            I need to implement a progress bar along with a status bar. I need to show the  progress and at the same time i need to change the contents of the status bar dynamically based on what script is being executed.

     

    Some thing like :

    Processing Script1.................

    Processing Script2.................

     

    etc

     

    Can any body tell me the best way to acheive this? Also i need to know if i can use a regular label control as a status bar?

     

    Thanks

    Mahesh

     

    Tuesday, January 2, 2007 7:06 PM

Answers

  • If you're preforming a lengthy operation you'll want to make sure you perform the processing on a background thread or the form will not be able update (defeating the purpose of a progress bar and a status bar...).  Easiest way to do this in .Net 2.0 is to use the BackgroundWorker class.  In your DoWork event handler simply use the BackgroundWorker.ReportProgress method--which will raise a ProgressChanged event that your form can process.  Be sure to set BackgroundWorker.WorkerReportsProgress to true (it's false by default).

    The reason BackgroundWorker is very useful for this sort of thing is because it ensures both the ProgressChanged and the RunWorkerCompleted events are executed on the same thread that created the BackgroundWorker object--if the BackgroundWorker object is created on the main/GUI thread then you don't have to worry about cross-thread WinForm control access.
    Tuesday, January 2, 2007 10:42 PM

All replies

  • hi Mahesh,

    moved thread to Windows forms forum

    Tuesday, January 2, 2007 7:40 PM
  • If you're preforming a lengthy operation you'll want to make sure you perform the processing on a background thread or the form will not be able update (defeating the purpose of a progress bar and a status bar...).  Easiest way to do this in .Net 2.0 is to use the BackgroundWorker class.  In your DoWork event handler simply use the BackgroundWorker.ReportProgress method--which will raise a ProgressChanged event that your form can process.  Be sure to set BackgroundWorker.WorkerReportsProgress to true (it's false by default).

    The reason BackgroundWorker is very useful for this sort of thing is because it ensures both the ProgressChanged and the RunWorkerCompleted events are executed on the same thread that created the BackgroundWorker object--if the BackgroundWorker object is created on the main/GUI thread then you don't have to worry about cross-thread WinForm control access.
    Tuesday, January 2, 2007 10:42 PM