How to Refresh the form?

I have created a simple archiving program. The zipping part of the archive program takes a while to finish. People who are using the program thinks that it freezes because when they click on it several time it say's not responding. It works if you just let it do it's thing. So I thought I better incorporate some things to tell the user what it's currently working on and the percent complete it is on all of them. So I put 2 labels on the form. One say's zipping and the other is suppost to show the file being zipped. The problem is that the form will not refresh when I type label4.Text = tmpVal; but when I put a message box right before it that just say's MessageBox.Show("Ok"); it refreshes. It's annoying to click the ok box 100 times so I would just like to know a more simple way to refresh the form1 box so that it displays the new text that I send it.

Answer this question

How to Refresh the form?

  • Patrick Barnes

    What about instead implementing a little bit of threading where your archiving is going on in a background thread and sends periodic events to the main form to update it’s progress

    This way the main form never appears stalled and your work still continues in the background.



  • Jereme Guenther

    hi,

    you can use Application.DoEvent() to force the message to be showen if this still to fast to catch use System.Threading.Thread.Sleep(duration in milliseconds like 1000 for one second)

    this slow down your application but show the user whats going on

    hope this helps



  • Daniel Booth ACITP

    hi,

    the normal way to do that is to show the user a new form just has a lable and a progress bar like the copy file dialog

    when you have recursive method this some how freez the GUI, and doesn't respond to the user till it finish, so you have to force your program to show result to the user the only way that i know is "forexample"

    label1.text = currentfilename;

    progressbar.value += 1;

    application.doevent();

    system.threading.thread.sleep(100);

    that will force the application to change the gui and will wait for 1/10 of second for the user to notice the changes

    you can use threads also in doing that but i prefer the above way particulary in this case

    hope this helps



  • flash77

    What do you mean threading. I send the file name to the form every time I am zipping it up. From the time the program starts zipping to the end it could go through as many as 900 files and take as long as 20 minutes. The entire time the only thing I have managed to get to work is the progress bar at the bottom. I just need it to appear like it's still doing something. What do I need to do to thread
  • juffowup

    Thanks this worked. I luckily didn't need to use the sleep command. Thanks for your help.


  • How to Refresh the form?