Exemplo n.º 1
0
 public FixedHeadTask(FixedHeadTaskInfo si)
 {
     IP      = si.ip;
     Port    = si.port;
     sendMsg = si.sendMsg;
     isGBK   = si.isGBK;
 }
Exemplo n.º 2
0
        private void FixedHeadTaskWorkerThread(object obj)
        {
            if (stopLoop())
            {
                return;
            }
            FixedHeadTaskInfo fixedHeadTaskInfo = (FixedHeadTaskInfo)obj;
            FixedHeadTask     fixedHeadTask     = new FixedHeadTask(fixedHeadTaskInfo);
            string            recvMsg           = fixedHeadTask.execute();

            if (this.IsHandleCreated)
            {
                this.BeginInvoke(richTextDelegate, Thread.CurrentThread.ManagedThreadId + "   " + recvMsg);
            }
            Thread.Sleep(1000);
        }
Exemplo n.º 3
0
        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("线程放置完成,立即执行!");
        }