示例#1
0
 /// <summary>
 ///     Releases unmanaged and - optionally - managed resources
 /// </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)
     {
         DisposableUtility.Dispose(ref _streamResource);
     }
 }
示例#2
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         DisposableUtility.Dispose(ref _serialPort);
     }
 }
示例#3
0
        private WaitHandle GetWaitHandle()
        {
            // check if needs to be created
            if (m_waitHandle == null)
            {
                // create a new manual reset event with the correct state
                bool             bWasCompleted = IsCompleted;
                ManualResetEvent mre           = new ManualResetEvent(bWasCompleted);

                if (Interlocked.CompareExchange(ref m_waitHandle, mre, null) != null)
                {
                    // we lost the race to create the event; dispose the unnecessary one
                    DisposableUtility.Dispose(ref mre);
                }
                else
                {
                    if (!bWasCompleted && IsCompleted)
                    {
                        // if the operation wasn't done when we created the event but is done now, set the event
                        m_waitHandle.Set();
                    }
                }
            }

            return(m_waitHandle);
        }
示例#4
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         DisposableUtility.Dispose(ref _udpClient);
     }
 }
示例#5
0
        public void DisposeNonDisposableObject()
        {
            object?obj = new object();

            DisposableUtility.DisposeObject(ref obj);
            Assert.IsNull(obj);
        }
示例#6
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         DisposableUtility.Dispose(ref _networkStream);
     }
 }
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (disposing)
            {
                DisposableUtility.Dispose(ref _client);
            }
        }
示例#8
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (disposing)
            {
                _masters.IfNotNull(m => m.Values.ForEach(client => DisposableUtility.Dispose(ref client)));
            }
        }
示例#9
0
        public void Dispose()
        {
            DisposableClass?d     = new DisposableClass();
            var             dCopy = d;

            Assert.IsFalse(d.IsDisposed);
            DisposableUtility.Dispose(ref d);
            Assert.IsNull(d);
            Assert.IsTrue(dCopy.IsDisposed);
        }
示例#10
0
        public void DisposeDisposableObject()
        {
            var d = new DisposableClass();

            DisposableClass?d2 = d;

            DisposableUtility.DisposeObject(ref d2);
            Assert.IsNull(d2);
            Assert.IsTrue(d.IsDisposed);
        }
示例#11
0
        public void DisposeStruct()
        {
            var count = 0;
            var ds    = new DisposableStruct(() => count++);

            // disposing should invoke the action
            DisposableUtility.DisposeObject(ref ds);
            Assert.AreEqual(1, count);

            // struct should have been replaced with default value, preventing second increment
            DisposableUtility.DisposeObject(ref ds);
            Assert.AreEqual(1, count);
        }
示例#12
0
        /// <summary>
        /// Waits for the asynchronous operation to complete, rethrowing any exception that occurred.
        /// </summary>
        public void EndInvoke()
        {
            // wait for the operation if necessary
            if (!IsCompleted)
            {
                GetWaitHandle().WaitOne();
            }

            // close the wait handle
            DisposableUtility.Dispose(ref m_waitHandle);

            // rethrow any exception that occurred during processing
            if (m_exception != null)
            {
                throw m_exception;
            }
        }
示例#13
0
 /// <summary>
 ///     Releases unmanaged and - optionally - managed resources
 /// </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)
         DisposableUtility.Dispose(ref _transport);
 }