For a simple example, let's say my event is something that hits the database.
SystemTimer Ticker = new SystemTimer() { Interval = TimeSpan.FromSeconds(5).TotalMilliseconds, AutoReset = true };
Ticker.Elapsed += HitTheDatabase;
and let's say HitTheDatabase
is async void
and leverages awaitability in ways like await connection.OpenAsync();
. Will this have any benefit as opopsed to just making the method void
and having it do connection.Open();
?
My understanding is that the elapsed event
- is a "fire and forget" (which is fine for my application's needs)
- runs the event in a different thread than the previous time it was called, if
Is that correct? Or can someone explain it to met in terms of graphs?
Like if I have
Ticker.Interval = 1000;
Ticket.Elapsed += Wait2Seconds;
and
private static void Wait2Seconds(object source, ElapsedEventArgs e)
{
Thread.Sleep(2000);
}
is that like
Time | 0:01 | 0:02 | 0:03 | 0:04 |
-----------------------------------------------------------
Thread 1 | |-------waiting------|
Thread 2 | |-------waiting------|
Thread 3 | |-------waiting------|
Thread 4 | |-------waiting------|
and would it be any different in an async
version using Task.Delay(1000)
?