/// <summary> /// Disposes this instance. /// </summary> /// <remarks> /// <para>If <see cref="Dispose()"/> is called multiple times, only the first call will execute the disposal code. Other calls to <see cref="Dispose()"/> will wait for the disposal to complete.</para> /// </remarks> public void Dispose() { var context = _context.TryGetAndUnset(); if (context is null) { _mre.Wait(); return; } try { context.Invoke(); } finally { _mre.Set(); } }
/// <summary> /// Disposes this instance. /// </summary> /// <remarks> /// <para>If <see cref="Dispose()"/> is called multiple times, only the first call will execute the disposal code. Other calls to <see cref="Dispose()"/> will wait for the disposal to complete.</para> /// </remarks> public void Dispose() { var context = _context.TryGetAndUnset(); if (context == null) { _tcs.Task.GetAwaiter().GetResult(); return; } try { context.Invoke(); } finally { _tcs.TrySetResult(null !); } }
/// <summary> /// Disposes this instance. /// </summary> /// <remarks> /// <para>If <see cref="Dispose()"/> is called multiple times, only the first call will execute the disposal code. Other calls to <see cref="Dispose()"/> will not wait for the disposal to complete.</para> /// </remarks> public void Dispose() => _context.TryGetAndUnset()?.Invoke();