L
L
littleguga2015-02-06 19:53:51
C++ / C#
littleguga, 2015-02-06 19:53:51

How to implement "running" points?

It would be desirable to make the display of waiting of process.
It should look like this: 1) .
2) ..
3) ...
4) .
And so in the cycle.
The question is how to implement this in c#?
This came to mind, but when launched, the form freezes and does not respond:

int i = 0;
int k = 0;
while (i < 1000)
{
  if (k == 0)
  {
    label1.Text = ".";
    k = 1;
  }
  else if (k == 1)
  {
    label1.Text = "..";
    k = 2;
  }
  else
  {
    label1.Text = "..";
    k = 0;
  }
    Thread.Sleep(100);
    i++;
}

ps.
In the task itself, I have already abandoned this idea in favor of a ProgressBar with Style=Marquee. But the question is now of purely academic interest.
pps
I am sure that somewhere in the world this has already been implemented. But to be honest, I don’t even know how to formulate the question “in a human way,” so I couldn’t google it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SHVV, 2015-02-06
@littleguga

If you have this code called on the user interface thread, then there is nothing surprising in this. You are blocking message queue processing and preventing controls from even redrawing themselves.
In "good" applications, it is not worth blocking the UI, you need to transfer the code to a parallel thread, and from there update the controls.
But in extreme cases, you can just periodically let the message queue "piss off" using Application.DoEvents ().

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question