ScheduledDisposable
Represents a disposable resource whose disposal invocation will be scheduled on the specified IScheduler.
using System.Reactive.Concurrency;
using System.Runtime.CompilerServices;
namespace System.Reactive.Disposables
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public sealed class ScheduledDisposable : ICancelable, IDisposable
{
private SingleAssignmentDisposableValue _disposable;
public IScheduler Scheduler { get; }
public IDisposable Disposable => _disposable.Disposable ?? System.Reactive.Disposables.Disposable.Empty;
public bool IsDisposed => _disposable.IsDisposed;
public ScheduledDisposable(IScheduler scheduler, IDisposable disposable)
{
if (scheduler == null)
throw new ArgumentNullException("scheduler");
Scheduler = scheduler;
ref SingleAssignmentDisposableValue disposable2 = ref _disposable;
if (disposable == null)
throw new ArgumentNullException("disposable");
disposable2.Disposable = disposable;
}
public void Dispose()
{
Scheduler.ScheduleAction(this, delegate(ScheduledDisposable scheduler) {
scheduler._disposable.Dispose();
});
}
}
}