{ private TaskCompletionSource<bool> SomethingChangedCompletionSource = new TaskCompletionSource<bool>(); public Task GetAwaitSomethingChangedTask() { // with a timeout of 60 seconds? return Task.WhenAny(Task.Delay(60_000), SomethingChangedCompletionSource.Task); } public void MarkSomethingChanged() { SomethingChangedCompletionSource.SetResult(true); SomethingChangedCompletionSource = new TaskCompletionSource<bool>(); } } // usage: // wait somewhere for something changed await GetAwaitSomethingChangedTask();
848900cookie-checkC# TaskCompletionSource / Promise Resolve