private void WorkThread() { while (true) { this.evn.WaitOne(); if (this.isConnect == false) { while (queue.Count > 0) { try { queue.Dequeue().Result.Close(); } catch { } } return; } SendPack pack = null; foreach (var q in queue) { if (q.IsSend == false) { pack = q; break; } } if (pack == null) { continue; } pack.IsSend = true; try { this.SockObj.BeginSend(pack.Data, 0, pack.Data.Length, SocketFlags.None, EndSend, pack); } catch { pack.IsSend = false; Thread.Sleep(300); continue; } bool hasNoSendData = false; lock (queue) { foreach (var q in queue) { if (q.IsSend == false) { hasNoSendData = true; } } } if (hasNoSendData) { this.evn.Set(); } } }
public void Attached(UInt32 requestId) { RequestId = requestId; ThreadId = (UInt32)Thread.CurrentThread.ManagedThreadId + ReflectInsightService.SessionId; SendPack = new SendPack(); IndentValue = new IndentValue(); CheckpointSet = new CheckpointSetContainer(); NamedCheckpoints = new Dictionary <String, CheckpointSetContainer>(); RequestMessageProperties = new MessagePropertyContainer(); States = new Dictionary <String, Object>(); Reset(); }
private void EndRecv(IAsyncResult result) { int recvCount = 0; try { recvCount = this.SockObj.EndReceive(result); } catch (Exception ex) { OnConnectionClose(); return; } if (recvCount == 0) { OnConnectionClose(); return; } this.dataList.AddRange(this.buffer.Take(recvCount)); var respSet = ResponseParse.GetInfo(this.dataList.ToArray()); if (respSet.Count > 0) { foreach (var resp in respSet) { SendPack sp = null; lock (this.queue) { if (queue.Count > 0) { sp = queue.Dequeue(); } } if (sp != null) { sp.Result.Send(this.dataList.Take(resp.BufferCount).ToArray()); } this.dataList.RemoveRange(0, resp.BufferCount); } } this.SockObj.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, EndRecv, null); }