Example #1
0
        private void _worker_DoWork(object sender, DoWorkEventArgs e)
        {
            _status = Status.Executing;
            TestingData data = e.Argument as TestingData;

            data.Result = "";
            Stopwatch watch = new Stopwatch();

            watch.Start();
            List <Task> list   = new List <Task>();
            string      errmsg = null;

            for (int i = 0; i < data.Count; i++)
            {
                Task t = new Task(RunTest, new Arg {
                    i = i + 1, Data = data
                });
                list.Add(t);
                t.Start();
                x = i;
            }
            try
            {
                Task.WaitAll(list.ToArray());
            }
            catch (Exception ex)
            {
                errmsg      = ex.Message;
                data.Result = errmsg;
            }
            watch.Stop();
            data.Time = watch.ElapsedMilliseconds;
            e.Result  = data;
            _status   = Status.Finished;
        }
Example #2
0
        private void _worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            progressbar.Visible = progressBar1.Visible = false;
            TestingData data = e.Result as TestingData;

            data.Result = data.Result;
            _list.Add(data);
            btnRun.Enabled = true;
            timer1.Stop();
            _status = Status.Finished;
        }
Example #3
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            int  taskcount = (int)numCount.Value;
            bool post      = rabPost.Checked;

            string[] urls        = txbUrl.Text.Split(';');
            string   postdata    = txbPost.Text;
            string   contentType = rabJson.Text;

            if (rabJson.Checked)
            {
                contentType = rabJson.Text;
            }
            else if (rabXml.Checked)
            {
                contentType = rabXml.Text;
            }
            else if (rdoUrlencoded.Checked)
            {
                contentType = rdoUrlencoded.Text;
            }
            else if (rabUpload.Checked)
            {
                contentType = rabUpload.Text;
                //contentType += ";boundary=---------123456789";
            }
            progressbar.Maximum = progressBar1.Maximum = taskcount;
            progressbar.Value   = progressBar1.Value = 0;
            i = 0;
            timer1.Start();
            progressbar.Visible = progressBar1.Visible = true;
            btnRun.Enabled      = false;
            foreach (var url in urls)
            {
                if (string.IsNullOrEmpty(url))
                {
                    continue;
                }
                BackgroundWorker _worker = new BackgroundWorker();
                _worker.DoWork             += _worker_DoWork;
                _worker.RunWorkerCompleted += _worker_RunWorkerCompleted;
                TestingData data = new TestingData {
                    Url = url, Method = post ? "post" : "get", Count = taskcount, PostData = postdata, ContentType = contentType
                };
                _worker.RunWorkerAsync(data);
                //while (_status != Status.Finished)
                //{
                //    Thread.Sleep(100);
                //}
            }
            //dgvData.DataSource = _list;
            //dgvData.Invalidate();
            //dgvData.FirstDisplayedScrollingRowIndex = dgvData.Rows.Count - 1;
        }