U
U
Untiwe2022-02-01 08:54:55
C++ / C#
Untiwe, 2022-02-01 08:54:55

How to subscribe to an event and not close the application?

Good afternoon. I want to make a small console application that would wait for some action in the system, the appearance of a file / device connection / loss of the Internet, etc. it doesn't matter at the moment. I can subscribe MyClass.MyFunction += System.SomeEvent But after that the control flow goes on and the application closes. The question is how to keep the application running and not consume a lot of resources?
PS While (true) {...} and Thread.Sleep take about 20% of CPU work

Answer the question

In order to leave comments, you need to log in

1 answer(s)
@
@insighter, 2022-02-01
_

Read keys.

while (true) {
      Console.ReadKey(true);
    }

PS I checked it myself, it does not take anything at all

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question