void EnumeratorCompleted(ProviderInfo info, bool canceled, Exception?ex) { Debug2.Assert(taskCompletionSource is not null); AttachableProcess[]? attachableProcesses; lock (lockObj) { wasCanceled |= canceled; if (ex is not null) { if (thrownExceptions is null) { thrownExceptions = new List <Exception>(); } thrownExceptions.Add(ex); } bool b = providerInfos.Remove(info); Debug.Assert(b); if (providerInfos.Count == 0) { attachableProcesses = result.ToArray(); result.Clear(); } else { attachableProcesses = null; } } if (attachableProcesses is not null) { if (thrownExceptions is not null) { taskCompletionSource.SetException(thrownExceptions); } else if (wasCanceled) { taskCompletionSource.SetCanceled(); } else { taskCompletionSource.SetResult(attachableProcesses); } thrownExceptions?.Clear(); thrownExceptions = null; processProvider.Dispose(); processProvider = null !; processNameRegexes = null !; processIds = null !; } }