Problem with Thread.Sleep

Is it possible that I call Thread.Sleep(1000)and the application can go to sleep for a very long amount of time, for example, in a minute or more?

It looks like this is happening in my application. I use Thread.Sleep, and the application seems to be hanging in the middle.

When I press Ctrl + Alt + Break, it points to a line immediately before calling Thread.Sleep. If I try to look at a variable, it says that the thread is in sleep mode and the variable is not in scope.

EDIT:

public void Write(string command)
        {
            _port.WriteLine("\r");
            _port.WriteLine(command + "\r");
            Thread.Sleep(100);
        }
+3
source share
4 answers

, , Thread.Sleep; , - . , , , - , , COM- : #

+3

, Thread.Sleep() , , , , , CPU .

, , , .

, , ( ..). , , , ( , , ), , , "", .

, . I/O, , -, .

1) , - , 2) - .

+2

, Thread.Sleep . Debug.WriteLine("About to call sleep"); ? ?

+1

Thread.Sleep () is a function of limited usability, in my opinion. I found that the passed timeout value seems to be a suggestion rather than a hard timeout value. I found the following code more accurate regarding the time interval:

        ManualResetEvent dummy = new ManualResetEvent(false);
        dummy.WaitOne(100);
        //...
+1
source

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


All Articles