Unable to update Label in windows form

  • Thread starter David-L. Nadeau
  • Start date
D

David-L. Nadeau

Hi !

I have a little problem. I have a process that runs when a user click a
button. The process is long to execute (+/- 5 minutes). So, I put a progress
bar and now I want to show the evolution of the process in a label (Step
1/5: Create... Step 2/5 Update....etc.) I don't know why but when I try to
update the text in my label in the middle of my process (Label.text = "Step
1/5: Create...", Label.text = "Step 2/5: Update...", etc.) the label doesn't
react. It comes available only when the process is finished.

What's wrong ?

David
 
J

Jan Tielens

Probably the UI thread waits while your other code is executing. But you can
update controls by invoking the Refresh method.
Label1.Text = "..."
Label1.Refresh
 
A

Armin Zingler

Jan Tielens said:
Probably the UI thread waits while your other code is executing. But
you can update controls by invoking the Refresh method.
Label1.Text = "..."
Label1.Refresh


Right, but ATTENTION for WinXP users: Due to a very very bad "design
change", calling Refresh is not sufficient anymore! :-(((((((((((((((((((((

3rd paragraph at
http://msdn.microsoft.com/library/e...ssagequeues/aboutmessagesandmessagequeues.asp

This is very bad because we are now FORCED to write multithreaded
applications or use Application.DoEvents although we don't want the user to
operate the application. It seems that the XP developers forgot that a
window is not only for *input* but also for *output*. A window that does not
process input messages does not necessarily mean that it does not display
something.

MSFT, please change this - at least optionally!
 
H

Herfried K. Wagner [MVP]

* "David-L. Nadeau said:
I have a little problem. I have a process that runs when a user click a
button. The process is long to execute (+/- 5 minutes). So, I put a progress
bar and now I want to show the evolution of the process in a label (Step
1/5: Create... Step 2/5 Update....etc.) I don't know why but when I try to
update the text in my label in the middle of my process (Label.text = "Step
1/5: Create...", Label.text = "Step 2/5: Update...", etc.) the label doesn't
react. It comes available only when the process is finished.

Call the label's 'Refresh' method.

Windows Forms + Multithreading
<http://www.devx.com/dotnet/Article/11358>
 
C

Chris Dunaway


I presume you're referring to this paragraph:

<QUOTE>
Microsoft Windows XP: If a top-level window stops responding to messages
for more than several seconds, the system considers the window to be hung.
In this case, the system hides the window and replaces it with a ghost
window that has the same Z order, location, size, and visual attributes.
This allows the user to move it, resize it, or even close the application.
However, these are the only actions available because the application is
actually hung. When in the debugger mode, the system does not generate a
ghost window.
</QUOTE>

Do you know if there is anyway to send a "Keep Alive" signal? Is DoEvents
the only thing that will do this?
 
A

Armin Zingler

Chris Dunaway said:
I presume you're referring to this paragraph:
yes

<QUOTE>
Microsoft Windows XP: If a top-level window stops responding to
messages for more than several seconds, the system considers the
window to be hung. In this case, the system hides the window and
replaces it with a ghost window that has the same Z order, location,
size, and visual attributes. This allows the user to move it, resize
it, or even close the application. However, these are the only
actions available because the application is actually hung. When in
the debugger mode, the system does not generate a ghost window.
</QUOTE>

Do you know if there is anyway to send a "Keep Alive" signal?

I think it is not possible.
Is
DoEvents the only thing that will do this?

Yes, DoEvents or putting the work in a different thread, so that the main UI
thread is not blocked.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top