示例#1
0
        /// <summary>
        /// Releases the managed resources (<see cref="managedResource"/>) used in this class.
        /// </summary>
        protected override void ReleaseManagedResources()
        {
            // Dispose of our managed resource if it is not null.
            managedResource?.Dispose();

            // Call the base method.
            base.ReleaseManagedResources();
        }
        public void Dispose()
        {
            if (disposed)
            {
                throw new ObjectDisposedException(typeof(ActionDisposable).Name);
            }

            Disposable?.Dispose();

            Disposable = null;

            disposed = true;
        }
示例#3
0
        /// <summary>
        /// <see cref="IDisposable.Dispose"/>
        /// </summary>
        public void Dispose()
        {
            this.disposed = true;

            foreach (KeyValuePair <UdpClient, IPEndPoint> P in this.ssdpOutgoing)
            {
                try
                {
                    P.Key.Dispose();
                }
                catch (Exception)
                {
                    // Ignore
                }
            }

            this.ssdpOutgoing.Clear();

            foreach (UdpClient Client in this.ssdpIncoming)
            {
                try
                {
                    Client.Dispose();
                }
                catch (Exception)
                {
                    // Ignore
                }
            }

            this.ssdpIncoming.Clear();

            foreach (ISniffer Sniffer in this.Sniffers)
            {
                if (Sniffer is IDisposable Disposable)
                {
                    try
                    {
                        Disposable.Dispose();
                    }
                    catch (Exception ex)
                    {
                        Log.Critical(ex);
                    }
                }
            }
        }
示例#4
0
                protected override void Dispose(bool disposing)
                {
                    if (disposing)
                    {
                        Disposable.Dispose(ref _firstDisposable);
                        Disposable.Dispose(ref _secondDisposable);

                        // clearing the queue should happen under the lock
                        // as they are plain Queue<T>s, not concurrent queues.
                        lock (_gate)
                        {
                            _firstObserver.Dispose();
                            _secondObserver.Dispose();
                        }
                    }
                    base.Dispose(disposing);
                }
示例#5
0
        public void Dispose()
        {
            if (Image != null)
            {
                Image.Dispose();
            }

            if (symbol_reader != null)
            {
                symbol_reader.Dispose();
            }

            if (assembly_resolver.value != null)
            {
                assembly_resolver.Dispose();
            }
        }
示例#6
0
            private static void Tick(object state)
            {
                var timer = (Timer)state;

                try
                {
                    var timerState = timer._state;
                    if (timerState != DisposedState)
                    {
                        timer._action(timerState);
                    }
                }
                finally
                {
                    Disposable.Dispose(ref timer._timer);
                }
            }
示例#7
0
        public void Dispose_TEST()
        {
            tlog.Debug(tag, $"DisposableWithDisposable START");

            try
            {
                Disposable disposable = new Disposable();
                disposable.Dispose();
            }
            catch (Exception e)
            {
                tlog.Error(tag, "Caught Exception" + e.ToString());
                Assert.Fail("Caught Exception" + e.ToString());
            }

            tlog.Debug(tag, $"DisposableWithDisposable END (OK)");
        }
示例#8
0
        /// <summary>
        /// Finalizes an instance of an actor.
        /// </summary>
        public override Task FinalizeInstance()
        {
            this.client?.Dispose();
            this.client = null;

            if (!(this.sniffer is null))
            {
                if (this.sniffer is IDisposable Disposable)
                {
                    Disposable.Dispose();
                }

                this.sniffer = null;
            }

            return(Task.CompletedTask);
        }
示例#9
0
            public override void OnCompleted()
            {
                Disposable.Dispose(ref _serialCancelable);

                lock (_gate)
                {
                    if (_hasValue)
                    {
                        ForwardOnNext(_value !);
                    }

                    ForwardOnCompleted();

                    _hasValue = false;
                    _id       = unchecked (_id + 1);
                }
            }
示例#10
0
        /// <summary>
        /// Disposes of attached content, given its ID.
        /// </summary>
        /// <param name="ContentId">Content ID</param>
        /// <returns>If content with the corresponding ID was found and disposed.</returns>
        public bool DisposeContent(string ContentId)
        {
            if (this.attachments.TryGetValue(ContentId, out object Obj))
            {
                this.attachments.Remove(ContentId);

                if (Obj is IDisposable Disposable)
                {
                    Disposable.Dispose();
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#11
0
        internal void CloseTab_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            int i = this.Tabs.SelectedIndex;

            if (i > 0)
            {
                if (this.Tabs.Items[i] is TabItem TabItem)
                {
                    object Content = TabItem.Content;
                    if (Content != null && Content is IDisposable Disposable)
                    {
                        Disposable.Dispose();
                    }
                }

                this.Tabs.Items.RemoveAt(i);
            }
        }
示例#12
0
        public void Merge_repeated_code_snd_test_only_one_thing()
        {
            // Execute after dispose.
            Assert.Throws <ObjectDisposedException>(
                () =>
            {
                var sut = new Disposable();
                sut.Dispose();
                sut.Execute();
            });

            // Repeated dispose
            Assert.Throws <ObjectDisposedException>(
                () =>
            {
                var sut = new Disposable();
                sut.Dispose();
                sut.Dispose();
            });
        }
示例#13
0
            private void OnCompleted(int index)
            {
                lock (_gate)
                {
                    _isDone[index] = true;

                    if (_isDone.All())
                    {
                        ForwardOnCompleted();
                    }
                    else
                    {
                        var subscriptions = Volatile.Read(ref _subscriptions);
                        if (subscriptions != null && subscriptions != Array.Empty <IDisposable>())
                        {
                            Disposable.Dispose(ref subscriptions[index]);
                        }
                    }
                }
            }
    // Section 10.14.4.3
    public void Dispose()
    {
        switch (state)
        {
        case State.Before: state = State.After; break;

        case State.Running: break;         // unspecified

        case State.Suspended: {
            state = State.Running;
            // finally occurs here
            d.Dispose();
            state = State.After;
        }
        break;

        case State.After: return;

        default: return;            // can't happen
        }
    }
示例#15
0
        /// <summary>
        /// Disposes contained objects and releases resources used by the <see cref="LifetimeContainer"/>.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                object[] array;

                lock (objects)
                {
                    array = objects.ToArray();

                    objects.Clear();
                }

                for (int i = array.Length - 1; i >= 0; i--)
                {
                    Disposable.Dispose(array[i]);
                }

                OnDisposed();
            }
        }
示例#16
0
                public void OnCompleted()
                {
                    lock (_parent._gate)
                    {
                        _parent._samplerAtEnd = true;

                        if (_parent._hasValue)
                        {
                            _parent._hasValue = false;
                            _parent.ForwardOnNext(_parent._value);
                        }

                        if (_parent._sourceAtEnd)
                        {
                            _parent.ForwardOnCompleted();
                        }
                        else
                        {
                            Disposable.Dispose(ref _parent._samplerDisposable);
                        }
                    }
                }
示例#17
0
        public void ObserveAdded()
        {
            var a = new Set <int>();

            a.Add(1);
            a.Add(2);

            var b = new Set <int>();

            b.Add(4);
            b.Add(8);

            var proxy     = new SetProxy <int>();
            var sum       = 0;
            var observers = new Disposable()
                            .Add(proxy.Added(item => sum   += item))
                            .Add(proxy.Removed(item => sum -= item));

            proxy.Target = a;
            Assert.AreEqual(3, sum);
            a.Remove(1);
            Assert.AreEqual(2, sum);

            proxy.Target = b;
            Assert.AreEqual(12, sum);
            b.Add(1);
            Assert.AreEqual(13, sum);

            proxy.Target = null;
            Assert.AreEqual(0, sum);

            b.Remove(8);
            proxy.Target = b;
            Assert.AreEqual(5, sum);
            observers.Dispose();
            b.Add(7);
            proxy.Target = null;
            Assert.AreEqual(5, sum);
        }
示例#18
0
            protected override void Dispose(bool disposing)
            {
                if (disposing)
                {
                    var subscriptions = Interlocked.Exchange(ref _subscriptions, Array.Empty <IDisposable>());
                    if (subscriptions != null && subscriptions != Array.Empty <IDisposable>())
                    {
                        for (var i = 0; i < subscriptions.Length; i++)
                        {
                            Disposable.Dispose(ref subscriptions[i]);
                        }

                        lock (_gate)
                        {
                            foreach (var q in _queues)
                            {
                                q.Clear();
                            }
                        }
                    }
                }
                base.Dispose(disposing);
            }
示例#19
0
        /// <summary>
        /// Returns an instance of the type <paramref name="Type"/>.
        /// </summary>
        /// <param name="ReturnNullIfFail">If null should be returned instead for throwing exceptions.</param>
        /// <param name="Type">Type of objects to return.</param>
        /// <param name="Arguments">Constructor arguments.</param>
        /// <returns>Instance of <paramref name="Type"/>.</returns>
        public object Instantiate(bool ReturnNullIfFail, Type Type, params object[] Arguments)
        {
            SingletonKey Key = new SingletonKey(Type, Arguments);
            object       Object;

            lock (instances)
            {
                if (instances.TryGetValue(Key, out Object))
                {
                    return(Object);
                }
            }

            Object = Types.Create(ReturnNullIfFail, Type, Arguments);
            if (Object is null)
            {
                return(null);
            }

            lock (instances)
            {
                if (instances.TryGetValue(Key, out object Object2))
                {
                    if (Object is IDisposable Disposable)
                    {
                        Disposable.Dispose();
                    }

                    return(Object2);
                }

                instances[Key] = Object;
            }

            return(Object);
        }
示例#20
0
        private void Drain()
        {
            if (Interlocked.Increment(ref _trampoline) != 1)
            {
                return;
            }

            for (; ;)
            {
                if (Volatile.Read(ref _isDisposed))
                {
                    while (_stack.Count != 0)
                    {
                        var enumerator = _stack.Pop();
                        enumerator.Dispose();
                    }

                    Disposable.Dispose(ref _currentSubscription);
                }
                else
                {
                    if (_stack.Count != 0)
                    {
                        var currentEnumerator = _stack.Peek();

                        var currentObservable = default(IObservable <TSource>);

                        try
                        {
                            if (currentEnumerator.MoveNext())
                            {
                                currentObservable = currentEnumerator.Current;
                            }
                        }
                        catch (Exception ex)
                        {
                            currentEnumerator.Dispose();
                            ForwardOnError(ex);
                            Volatile.Write(ref _isDisposed, true);
                            continue;
                        }

                        IObservable <TSource>?next;

                        try
                        {
                            next = Unpack(currentObservable);
                        }
                        catch (Exception ex)
                        {
                            if (!Fail(ex))
                            {
                                Volatile.Write(ref _isDisposed, true);
                            }
                            continue;
                        }

                        if (next != null)
                        {
                            var nextSeq = Extract(next);
                            if (nextSeq != null)
                            {
                                if (TryGetEnumerator(nextSeq, out var nextEnumerator))
                                {
                                    _stack.Push(nextEnumerator);
                                    continue;
                                }

                                Volatile.Write(ref _isDisposed, true);
                                continue;
                            }

                            // we need an unique indicator for this as
                            // Subscribe could return a Disposable.Empty or
                            // a BooleanDisposable
                            var sad = ReadyToken.Ready;

                            // Swap in the Ready indicator so we know the sequence hasn't been disposed
                            if (Disposable.TrySetSingle(ref _currentSubscription, sad) == TrySetSingleResult.Success)
                            {
                                // subscribe to the source
                                var d = next.SubscribeSafe(this);

                                // Try to swap in the returned disposable in place of the Ready indicator
                                // Since this drain loop is the only one to use Ready, this should
                                // be unambiguous
                                var u = Interlocked.CompareExchange(ref _currentSubscription, d, sad);

                                // sequence disposed or completed synchronously
                                if (u != sad)
                                {
                                    d.Dispose();
                                    if (u == BooleanDisposable.True)
                                    {
                                        continue;
                                    }
                                }
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else
                        {
                            _stack.Pop();
                            currentEnumerator.Dispose();
                            continue;
                        }
                    }
                    else
                    {
                        Volatile.Write(ref _isDisposed, true);
                        Done();
                    }
                }

                if (Interlocked.Decrement(ref _trampoline) == 0)
                {
                    break;
                }
            }
示例#21
0
 public void Dispose()
 {
     pdb_file.Dispose();
 }
示例#22
0
 public void Dispose()
 {
     Disposable.Dispose();
 }
示例#23
0
文件: Image.cs 项目: zwinter/ET
 public void Dispose()
 {
     Stream.Dispose();
 }
示例#24
0
 public void Dispose()
 {
     _cancellationTokenSource.Dispose();
     Disposable.Dispose();
 }
示例#25
0
 public void Dispose() => backing.Dispose();
 /// <summary>
 /// アプリが閉じられる時
 /// </summary>
 private void Close()
 {
     Disposable.Dispose();
 }
示例#27
0
 public void Run()
 {
     var disposable = new Disposable();
     disposable.Dispose();
     Assert.IsTrue(DisposeTracker.HasDisposedBeenCalled);
 }
示例#28
0
 public void Dispose()
 {
     Disposable.Dispose(ref _cancel);
 }
示例#29
0
        /// <summary>
        /// Stops the gateway.
        /// </summary>
        public static void Stop()
        {
            IDisposable Disposable;

            Log.Informational("Server shutting down.");

            /*
             * if (databaseProvider != null)
             *      File.WriteAllText(appDataFolder + "Stop.xml", databaseProvider.ExportXml(true).Result);
             */

            if (gatewayRunning != null)
            {
                gatewayRunning.Release();
                gatewayRunning.Dispose();
                gatewayRunning = null;
            }

            if (ibbClient != null)
            {
                ibbClient.Dispose();
                ibbClient = null;
            }

            if (httpxServer != null)
            {
                httpxServer.Dispose();
                httpxServer = null;
            }

            if (provisioningClient != null)
            {
                provisioningClient.Dispose();
                provisioningClient = null;
            }

            if (thingRegistryClient != null)
            {
                thingRegistryClient.Dispose();
                thingRegistryClient = null;
            }

            if (concentratorServer != null)
            {
                concentratorServer.Dispose();
                concentratorServer = null;
            }

            if (xmppClient != null)
            {
                using (ManualResetEvent OfflineSent = new ManualResetEvent(false))
                {
                    xmppClient.SetPresence(Availability.Offline, string.Empty, (sender, e) => OfflineSent.Set());
                    OfflineSent.WaitOne(1000);
                }

                foreach (ISniffer Sniffer in xmppClient.Sniffers)
                {
                    XmppClient.Remove(Sniffer);

                    Disposable = Sniffer as IDisposable;
                    if (Disposable != null)
                    {
                        Disposable.Dispose();
                    }
                }

                xmppClient.Dispose();
                xmppClient = null;
            }

            if (connectionTimer != null)
            {
                connectionTimer.Dispose();
                connectionTimer = null;
            }

            if (coapEndpoint != null)
            {
                coapEndpoint.Dispose();
                coapEndpoint = null;
            }

            if (webServer != null)
            {
                foreach (ISniffer Sniffer in webServer.Sniffers)
                {
                    webServer.Remove(Sniffer);

                    Disposable = Sniffer as IDisposable;
                    if (Disposable != null)
                    {
                        Disposable.Dispose();
                    }
                }

                webServer.Dispose();
                webServer = null;
            }

            clientEvents = null;
        }
示例#30
0
文件: D3D.cs 项目: rasmus-z/tv
 public void Dispose()
 {
     Disconnect();
     Disposable.Dispose(ref Device);
 }
 protected override void EvStateExit()
 {
     Disposable.Dispose();
     Disposable = null;
 }