Пример #1
0
        public void Close(int nID)
        {
            Peer c = GetPeer(nID);

            if (c == null)
            {
                return;
            }
            if (c.Connected)
            {
                try
                {
                    if (c.client.Client.Blocking)
                    {
                        c.client.Client.Shutdown(SocketShutdown.Both);
                        c.client.Client.Close();
                    }
                    c.client.Close();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                }
            }

            locker.AcquireWriterLock(Timeout.Infinite);
            peers.Remove((int)nID);
            locker.ReleaseWriterLock();

            handler.OnClose(nID);
        }
Пример #2
0
 private static void WriterProc()
 {
     for (int i = 0; i < 1000; i++)
     {
         rWLock.AcquireWriterLock();
         resource++;
         rWLock.ReleaseWriterLock();
     }
 }
Пример #3
0
 public void Clear()
 {
     fCacheLock.AcquireWriterLock();
     try {
         fQueue.Clear();
         fTileCache.Clear();
         fMemoryCacheSize = 0;
     } finally {
         fCacheLock.ReleaseWriterLock();
     }
 }
Пример #4
0
 // 获取并释放写者锁,发生超时会取消操作
 static void WriteToResource(Random rnd, int timeOut)
 {
     try {
         rwl.AcquireWriterLock(timeOut);
         try {
             resource = rnd.Next(500);
             Display("writes resource value " + resource);
             Interlocked.Increment(ref writes);
         }
         finally {
             rwl.ReleaseWriterLock();
         }
     }
     catch (ApplicationException) {
         // 超时
         Interlocked.Increment(ref writerTimeouts);
     }
 }
Пример #5
0
 protected void ReleaseWriterLock()
 {
     RWLock.ReleaseWriterLock();
 }