using System.Threading.Tasks;
public static Timer CreateTimer(TimerCallback cb, AutoResetEvent autoResetEvent)
return new Timer(cb, autoResetEvent, 1000, 250);
public static void Main()
var autoResetEvent = new AutoResetEvent(false);
var timer = CreateTimer(OnTimeout, autoResetEvent);
autoResetEvent.WaitOne();
Thread.Sleep(TimeSpan.FromSeconds(1));
public static async void OnTimeout(object? state)
if (state is AutoResetEvent are)
await Task.Run(() => are.Set());
Console.WriteLine("Signaled completion");