In my application, I created a "Timer" (System.Windows.Forms) that runs every 1 second. In the "tick" event, I put a await Task.Run.
For some reason the tick stops running after a while (because it does not print the date and time on the console).
Class x {
public Timer timer {get; set;}
public void f()
{
timer = new Timer();
timer.Tick += new EventHandler(this.tick);
timer.Enabled = false;
timer.Interval = 1000;
timer.Start();
}
private async void tick(object sender, EventArgs e)
{
this.status = ProcessoStatus.TRABALHANDO;
this.timer.Stop();
try
{
await Task.Run(() => this.processo());
}
catch
{}
this.timer.Start();
this.status = ProcessoStatus.OCIOSO;
}
public void processo()
{
Console.WriteLine(DateTime.Now);
}
}