コード例 #1
0
        public void Dispose()
        {
            if (isDisposed_)
            {
                return;
            }

            lock (ThreadLock) {
                if (sendingTaskAwaiter_ != null)
                {
                    ThreadCancellationTokenSource.Cancel();
                    SendEvent.Set();
                    sendingTaskAwaiter_.Value.GetAwaiter().OnCompleted(() => {
                        SendEvent.Dispose();
                        ThreadCancellationTokenSource.Dispose();
                    });
                }
                else
                {
                    SendEvent.Dispose();
                    ThreadCancellationTokenSource.Dispose();
                }
            }
            DataSender.Dispose();

            GC.SuppressFinalize(this);
            isDisposed_ = true;
        }
コード例 #2
0
 protected virtual void Dispose(bool disposing)
 {
     if (m_disposed)
     {
         return;
     }
     if (disposing)
     {
         //释放托管资源
         m_connectSocket            = null;
         m_asyncReceiveBuffer       = null;
         ReceiveEventArgs.UserToken = null;
         SendEventArgs.UserToken    = null;
     }
     //释放非托管资源
     ReceiveEventArgs.Dispose();
     SendEventArgs.Dispose();
     SendEvent.Dispose();
     m_disposed = true;
 }