public void SendThreadEntryPoint(object state) { try { Queue workQueue = new Queue(); // loop... while (true) { WaitHandle[] handles = new WaitHandle[2]; handles[0] = StopEvent; handles[1] = DataReady; if (WaitHandle.WaitAny(handles) == 0) { break; } else if (_Socket != null && _Socket.Connected) { // not disconnected // go through the queue... TransmitLock.AcquireWriterLock(-1); try { workQueue.Clear(); foreach (string message in TransmitQueue) { workQueue.Enqueue(message); } TransmitQueue.Clear(); } catch { } finally { TransmitLock.ReleaseWriterLock(); } // loop the outbound messages... foreach (string message in workQueue) { SocketStateObject so2 = new SocketStateObject(_Socket); byte[] buff = Encoding.ASCII.GetBytes(message); // send it... System.IAsyncResult iar; iar = _Socket.BeginSend(buff, 0, buff.Length, 0, new AsyncCallback(AsynchSendCallback), so2); } } } } catch { } }
public void ReceiveThreadEntryPoint(object state) { try { // loop... while (true) { WaitHandle[] handles = new WaitHandle[1]; handles[0] = StopEvent; if (_Socket != null && _Socket.Connected) { // not disconnected try { // start the recieve operation System.IAsyncResult iar; SocketStateObject so2 = new SocketStateObject(_Socket); iar = _Socket.BeginReceive(so2.buffer, 0, SocketStateObject.BUFFER_SIZE, 0, new AsyncCallback(AsynchReadCallback), so2); if (WaitHandle.WaitAny(handles) == 0) { break; } } catch { } } } } catch { } }