Answer the question
In order to leave comments, you need to log in
How to stop the program from stopping?
There is a timer, every 5 minutes which methods are executed in timer.elapsed, only because there is nothing else, the timer is created and the program ends before reaching 5 minutes.
So far, I have made an infinite counter in while (true), how should I solve such a problem correctly?
Answer the question
In order to leave comments, you need to log in
var timer = new Timer((e) => { });
timer.Change(0, 1000);
Console.ReadKey();
It depends on what you need and how reliable it should be. In the simplest case, it is better to separate the program that executes the methods and the program that executes the timer so that the timer is not covered in case of an execution. You can also use while (true), just hang Thread.Sleep (five minutes) in it for the waiting time
It all depends on your architecture, if this is a simple console application and you don’t need anything other than a timer, then I would do this:
Timer timer = new Timer((obj) =>
{
Console.WriteLine("Hello");
});
timer.Change(0, 1000);
Thread.CurrentThread.Suspend();
Usually, when they say that something does not work, they attach the code. I sat and thought, and what does WPF have to do with it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question