Exemplo n.º 1
0
 public void RegisterForDisposal(IDisposable disposable)
 {
     if (_disposables == null)
     {
         _disposables = new QueueLite <IDisposable>();
     }
     _disposables.Enqueue(disposable);
 }
Exemplo n.º 2
0
        void DisposeAndNotify()
        {
            if (_disposables == null || _disposables.Count == 0)
            {
                return;
            }

            // Make sure the Dispose method for every disposable instances is only called once.
            while (_disposables.Count > 0)
            {
                var disposable = _disposables.Dequeue();
                disposable.Dispose();
            }
            _disposables.Discard();
            _disposables = null;
            LifetimeScopeEnded.Invoke(GetLifetimeScopeEndedEventArgs());
        }