I have many backend console App, need to use a timer on it I use the following To initiate and maintain timer on console App in main method :
System.Timers.Timer statustimer =
new System.Timers.Timer(
double.Parse(ConfigurationManager.AppSettings["NotificationSendPeriod"]));
statustimer.Elapsed += ((sender, eventArgs) =>
{
try
{
ProcessData();
}
catch (Exception e)
{
Console.WriteLine(e);
}
});
statustimer.Enabled = true; Console.ReadLine();
and in ProcessData I initiate a new thread each time the method Call ( I control the number of parallel running by a counter From app.config
public static async Task<bool> ProcessData()
{
try
{
new Thread(() =>
{
// Do work here
}).Start();
return true;
}
catch (Exception exception)
{
Console.WriteLine(exception);
_logInstance?.Error(exception, $"{exception.Message}\n{exception.StackTrace}");
return false;
}
}
I noticed by usign the code above after a while the console app close even though am using Console.Readline() , or hang up and nothing happen
any idea what's wrong in the above code and how to fix