예제 #1
0
        private void button4_Click(object sender, EventArgs e)
        {
            if (Serial.IsOpen)
            {
                if (btnDer.Checked)
                {
                    Send(DerValue0);
                    if (keyLen >= 1)
                    {
                        Send(DerValue1);
                        Send(DerValue2);
                        Send(DerValue3);
                        Send(DerValue4);
                    }
                }
                else if (btnData.Checked)
                {
                    System.Threading.Timer timer = new System.Threading.Timer(timer_callback);

                    timer.Change(0, 1000);

                    progressBar1.Value   = 0;
                    progressBar1.Maximum = bytelen;

                    textBox_msg.AppendText("[" + DateTime.Now.ToString() + "]");
                    DateTime startTime = DateTime.Now;

                    for (int i = 0; i <= bytelen; i++)
                    {
                        Send(DV[i]);
                        textBox_msg.AppendText("[" + mm + ":" + ss + "]" + "\r\n" + i + "/" + bytelen + "\r\n");
                        if (progressBar1.Value != progressBar1.Maximum)
                        {
                            progressBar1.Value++;
                        }
                    }

                    /*
                     * Parallel.For(0, bytelen, (i) =>
                     * {
                     *  Send(DV[i]);
                     *  textBox_msg.AppendText("[" + mm + ":" + ss + "]" + "\r\n" + i + "/" + bytelen + "\r\n");
                     *  progressBar1.Value++;
                     * });
                     */

                    DateTime endTime = DateTime.Now;
                    TimeSpan elapsed = endTime - startTime;

                    textBox_msg.AppendText("complete! \r\n");
                    textBox_msg.AppendText("[" + DateTime.Now.ToString() + "]\r\n");
                    textBox_msg.Text += elapsed;

                    timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
                    timer.InitializeLifetimeService();
                    timer.Dispose();

                    progressBar1.Value = 0;
                }
            }
            else
            {
                MessageBox.Show("port is not opend");
            }
        }