experiments/csharp/E010-ThreadTest/Program.cs

21 lines
469 B
C#
Raw Normal View History

2024-05-04 21:16:52 +01:00
using System.Timers;
using Timer = System.Timers.Timer;
var timer = new Timer
{
Interval = 1000,
Enabled = true
};
timer.Elapsed += TimerOnElapsed;
Console.WriteLine($"Calling start in thread {Environment.CurrentManagedThreadId}");
timer.Start();
Console.ReadLine();
static void TimerOnElapsed(object? sender, ElapsedEventArgs e)
{
(sender as Timer)?.Stop();
Console.WriteLine($"Elapsed raised in thread {Environment.CurrentManagedThreadId}");
}