public void OnNotifyIdle() { if (activeTaskCompletionSource != null) { ActiveTaskCompletionSource activeTaskCompletionSource = this.activeTaskCompletionSource; this.activeTaskCompletionSource = null; if (activeTaskCompletionSource.TrySetCompleted()) { return; } } // During ActivateAsync, idle can be null. idle?.Set(); }
private async Task RunInstanceWithActiveTaskCompletionSourceProtectionAsync <TResponseParameter>(TaskCompletionSource <TResponseParameter> taskCompletionSource, ActiveTaskCompletionSource.ProtectionLevel protectionLevel) where TResponseParameter : class { try { activeTaskCompletionSource = new ActiveTaskCompletionSource <TResponseParameter>(taskCompletionSource, protectionLevel); await instance.RunAsync(); } catch { activeTaskCompletionSource = null; throw; } }