void OnAnnouncementSendsCompleted(IAsyncResult result) { if (!result.CompletedSynchronously) { Exception error = null; try { AnnouncementSendsAsyncResult.End(result); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } error = e; } if (error != null) { CallCompleteOnce(false, error); } else { if (Interlocked.Increment(ref this.completions) == innerResults.Length) { CallCompleteOnce(false, null); } } } }
public void Start(TimeSpan timeout, bool canCompleteSynchronously) { if (this.IsCompleted || this.cancelled) { return; } bool synchronousCompletion = canCompleteSynchronously; Exception error = null; bool complete = false; try { for (int i = 0; i < this.innerResults.Length; i++) { this.innerResults[i].Start(timeout); if (this.innerResults[i].CompletedSynchronously) { AnnouncementSendsAsyncResult.End(this.innerResults[i]); complete = (Interlocked.Increment(ref this.completions) == innerResults.Length); } else { synchronousCompletion = false; } } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } error = e; } if (error != null) { CallCompleteOnce(synchronousCompletion, error); } else if (complete) { CallCompleteOnce(synchronousCompletion, null); } }