-
Notifications
You must be signed in to change notification settings - Fork 144
Open
Labels
Lib:ThreadingDotNext.Threading libraryDotNext.Threading libraryneed infoClarification from reporter expectedClarification from reporter expected
Description
use case:
Class MyClass : BackgroundService {
private readonly AsyncAutoResetEvent _wakeEvent = new(false);
protected override async Task ExecuteAsync(CancellationToken ct) {
const int delay = 100;
var timer = Stopwatch.StartNew();
while (!ct.IsCancellationRequested) {
var remaining = (double)Math.Max(0, delay - timer.ElapsedMilliseconds);
await _wakeEvent.WaitAsync(TimeSpan.FromMilliseconds(remaining), CancellationToken.None);
timer.Restart();
}
}
Metadata
Metadata
Assignees
Labels
Lib:ThreadingDotNext.Threading libraryDotNext.Threading libraryneed infoClarification from reporter expectedClarification from reporter expected