Why does the console pause my code when I click on the scroll bar

Run this code in a C # console application:

long last = 0;
long curr = Stopwatch.GetTimestamp();

while (true)
{
    last = curr;
    curr = Stopwatch.GetTimestamp();
    var delta = ((curr - last) / (float)Stopwatch.Frequency) * 1000;
    Console.WriteLine(delta);
    Thread.Sleep(50);
 }

This source should print some stable numbers, such as

  • ...
  • 62.234235
  • 62.123134
  • 62.589342
  • 62.423423
  • ...

And while he holds the scroll button for a few seconds. While you are holding the button, the outputs should stop because the thread has slept ....

The next exit when u release is smt. eg:

  • ...
  • 62.234235
  • 62.123134 <--- Holding the scroll button
  • 2540.342112 <--- Release
  • 62.589342
  • 62.423423
  • ...

Now my question is: Is there a way for the Console not to tell my stream a draw when I scroll?

+4
source share
3 answers

No, there is no way.

Console.WriteLine - blocking operation . , , .

, , 50+. .

+3

:

ConcurrentQueue<float> deltasQueue;

, , , Console.WriteLine(delta) delta deltasQueue.

, , , deltasQueue Console.WriteLine(delta).

, , deltas, . , . , , .

+2

You block the user interface that executes any code while holding down the scroll button. Therefore, your program is paused.

When you release, the code starts and you get a printout out of time.

0
source

Source: https://habr.com/ru/post/1542950/


All Articles