I am writing a console application that does a certain job of the scheduler and writes the output to the console. Everything is fine, but when I click on the console, it stops working and waits for my right click. After that, he continues to work.
I thought that he simply did not write the text to the console and did what was needed, but no, he was waiting for my interaction. I can rewrite this code in WinForms or WPF, but I think it can be solved differently. Here is my code
static void Main(string[] args)
{
Console.WriteLine("Started...");
var timer = new System.Timers.Timer(1000);
timer.Elapsed += timer_Elapsed;
timer.Start();
Console.ReadLine();
}
static void timer_Elapsed(object sender, ElapsedEventArgs e)
{
Console.WriteLine("Writing to file " + DateTime.Now.ToString());
System.IO.File.AppendAllLines(@"C:\Temp\log.txt",
new[] { DateTime.Now.ToString()});
}
After clicking on the console, it pauses the time it takes to add the log.txt file. Any ideas how to fix this? Thanks.
source
share