Skip to content

Possible memory leaks with AsyncAutoResetEvent #279

@KostyaLocal

Description

@KostyaLocal

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 libraryneed infoClarification from reporter expected

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions