Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Updating a Progress Form

Updating a Progress Form

Scheduled Pinned Locked Moved C#
winformsquestionannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    danielk_
    wrote on last edited by
    #1

    I have a windows forms app which goes and does some processing. While this processing is being done I have created a progress form which I want to show the current progress (this is not working correctly). The code is:

    ProgressForm frm = new ProgressForm();   //this is just a simple Form
    
    frm.ProgressText = "Do step 1...";                  //this sets some text on a label
    DoStep1();
    
    frm.ProgressText = "Do step 2...";
    DoStep2();
    
    frm.ProgressText = "Do step 3...";
    DoStep3();
    
    frm.ProgressText = "Completed";
    

    This code will show the progress form, but it will not update the label text until all the steps have completed, then the progress form show "Completed", while the processing is still happening it shows nothing. Anyone know a solution? thanks

    M 1 Reply Last reply
    0
    • D danielk_

      I have a windows forms app which goes and does some processing. While this processing is being done I have created a progress form which I want to show the current progress (this is not working correctly). The code is:

      ProgressForm frm = new ProgressForm();   //this is just a simple Form
      
      frm.ProgressText = "Do step 1...";                  //this sets some text on a label
      DoStep1();
      
      frm.ProgressText = "Do step 2...";
      DoStep2();
      
      frm.ProgressText = "Do step 3...";
      DoStep3();
      
      frm.ProgressText = "Completed";
      

      This code will show the progress form, but it will not update the label text until all the steps have completed, then the progress form show "Completed", while the processing is still happening it shows nothing. Anyone know a solution? thanks

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      You don't give your label a chance to paint itself because the main (UI-)Thread is busy performing your steps. Either put a call to Application.DoEvents(); after each text update (beware - that's the quick&dirty way that can lead to other, unexpected problems) or do it correctly: Put the calls to DoStepN() into a separate thread so your UI will remain responsive. The class BackgroundWorker makes it quite easy.

      Regards, mav -- Black holes are the places where God divided by 0...

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups