public FixedByteTask(FixedByteTaskInfo si) { IP = si.ip; Port = si.port; sendMsg = si.sendMsg; isGBK = si.isGBK; headLen = si.headLen; }
private void FixedByteTaskWorkerThread(object obj) { if (stopLoop()) { return; } FixedByteTaskInfo fixedByteTaskInfo = (FixedByteTaskInfo)obj; FixedByteTask fixedByteTask = new FixedByteTask(fixedByteTaskInfo); string recvMsg = fixedByteTask.execute(); if (this.IsHandleCreated) { this.BeginInvoke(richTextDelegate, Thread.CurrentThread.ManagedThreadId + " " + recvMsg); } Thread.Sleep(1000); }
public void startTask(long count) { string msgType = cbxMsgType.Text.Trim(); /*int count; * if (taskMode) //true:发送一次 * { * count = 1; * } * else * { * count = Int32.Parse(cbxThreadCount.Text.Trim()); * }*/ if (msgType.Equals("整型定长")) { FixedHeadTaskInfo fixedHeadTasknfo = new FixedHeadTaskInfo(cbxIPAddress.Text.Trim(), txtPort.Text.Trim(), rcSendText.Text.Trim(), rdBtnGBK.Checked); //启动工作者线程 for (int i = 0; i < count; i++)//不能在这里终止,循环速度太快。所以在子线程里判断状态 { ThreadPool.QueueUserWorkItem(new WaitCallback(FixedHeadTaskWorkerThread), fixedHeadTasknfo); } } else if (msgType.Equals("定长字节")) { FixedByteTaskInfo fixedByteTasknfo = new FixedByteTaskInfo(cbxIPAddress.Text.Trim(), txtPort.Text.Trim(), rcSendText.Text.Trim(), rdBtnGBK.Checked, txtMsgHeadLength.Text.Trim()); //启动工作者线程 for (int i = 0; i < count; i++) { ThreadPool.QueueUserWorkItem(new WaitCallback(FixedByteTaskWorkerThread), fixedByteTasknfo); } } else if (msgType.Equals("不定长字节")) { ByteTaskInfo byteTasknfo = new ByteTaskInfo(cbxIPAddress.Text.Trim(), txtPort.Text.Trim(), rcSendText.Text.Trim(), rdBtnGBK.Checked); //启动工作者线程 for (int i = 0; i < count; i++) { ThreadPool.QueueUserWorkItem(new WaitCallback(byteTaskWorkerThread), byteTasknfo); } } else if (msgType.Equals("HTTP参数")) { HttpParamTaskInfo httpParamTaskInfo = new HttpParamTaskInfo(txtURI.Text.Trim(), rcSendText.Text.Trim()); //启动工作者线程 for (int i = 0; i < count; i++) { ThreadPool.QueueUserWorkItem(new WaitCallback(HttpParamTaskWorkerThread), httpParamTaskInfo); } } else if (msgType.Equals("MQ报文")) { MQTaskInfo mqTaskInfo = new MQTaskInfo(rcSendText.Text.Trim(), chkMQMode.Checked); //启动工作者线程 for (int i = 0; i < count; i++) { ThreadPool.QueueUserWorkItem(new WaitCallback(MQTaskWorkerThread), mqTaskInfo); } } Console.WriteLine("线程放置完成,立即执行!"); }