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 form with text during long process

Updating form with text during long process

Scheduled Pinned Locked Moved C#
questionalgorithmsannouncement
3 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.
  • G Offline
    G Offline
    Glenn E Lanier II
    wrote on last edited by
    #1

    I have a form with a label (name = labelStatus) that I would like to update during a lengthy process (e.g. while scanning all files on drive - show filename). void TimeConsumingMethod() { string fileName = "C:\Temp\A.txt"; // Do some stuff here labelStatus.Text = string.Format("Searching {0}", fileName); // Do more stuff here // Finally finished. } It doesn't seem to update the label until the method finishes. I've tried to invalidate the form after setting the new text, but that really doesn't make a visible difference. How can I accomplish this? --G

    Z 1 Reply Last reply
    0
    • G Glenn E Lanier II

      I have a form with a label (name = labelStatus) that I would like to update during a lengthy process (e.g. while scanning all files on drive - show filename). void TimeConsumingMethod() { string fileName = "C:\Temp\A.txt"; // Do some stuff here labelStatus.Text = string.Format("Searching {0}", fileName); // Do more stuff here // Finally finished. } It doesn't seem to update the label until the method finishes. I've tried to invalidate the form after setting the new text, but that really doesn't make a visible difference. How can I accomplish this? --G

      Z Offline
      Z Offline
      zagzagzag
      wrote on last edited by
      #2

      As far as i know you have to update the label your self: labelStatus.Text = "The stuff you want"; labelStatus.Update(); or: labelStatus.Text = "The stuff you want"; labelStatus.Update(); this.Update(); and finally you can write the following before the lenghty process starts: Application.DoEvents(); Hope it works!

      G 1 Reply Last reply
      0
      • Z zagzagzag

        As far as i know you have to update the label your self: labelStatus.Text = "The stuff you want"; labelStatus.Update(); or: labelStatus.Text = "The stuff you want"; labelStatus.Update(); this.Update(); and finally you can write the following before the lenghty process starts: Application.DoEvents(); Hope it works!

        G Offline
        G Offline
        Glenn E Lanier II
        wrote on last edited by
        #3

        zagzagzag wrote: Hope it works! :-D Thanks -- this worked perfectly.

        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