1

我正在为 RFID 阅读器开发一个应用程序。我有一个具有以下操作的按钮:

private void btnWrite_Click(object sender, EventArgs e)
        {
            this.CheckPort = true;
            this.DetectCOMPort();
            bool readerOK = this.IsReaderConnected(this.lblCom.Text);
            bool flag = !readerOK;
            if (flag)
            {
                this.CheckPort = true;
                this.DetectCOMPort();
            }
            else
            {
                byte[] raspunsCitire = this.CitesteTag(this.lblCom.Text);
                flag = raspunsCitire == null;
                if (flag)
                {
                    MessageBox.Show("The label couldn't be read!");
                }
                else
                {
                    string scrisInTag = this.FormateazaCitire(raspunsCitire);
                    string[] campuriScrise = this.DecompileazaMesaj(scrisInTag, '|');
                    this.btnValid.Enabled = true;
                    this.txtEvenim.Enabled = true;
                    this.txtEvenim.Text = campuriScrise[0];
                    this.txtNume.Enabled = true;
                    this.txtNume.Text = campuriScrise[1];
                    this.txtPrenume.Enabled = true;
                    this.txtPrenume.Text = campuriScrise[2];
                    this.txtComp.Enabled = true;
                    this.txtComp.Text = campuriScrise[3];
                    this.txtFunc.Enabled = true;
                    this.txtFunc.Text = campuriScrise[4];
                    this.txtTit.Enabled = true;
                    this.txtTit.Text = campuriScrise[5];
                    this.Refresh();
                }
            }
        }

我想要的是每 2 秒重复读取一次标签,而不是显示MessageBox.Show("The label couldn't be read!");. 对于另一种情况,当读取标签时,我希望此过程停止 20 秒,然后在 20 秒后每隔 2 秒重新开始读取。有可能以某种方式做到这一点吗?先感谢您!

4

1 回答 1

1

你有没有研究过定时器控制?

Timer timer = new Timer();

timer.Tick += new EventHandler(timer_Tick); // Everytime timer ticks, timer_Tick will be called
timer.Interval = (1000) * (10);             // Timer will tick evert 10 seconds
timer.Enabled = true;                       // Enable the timer
timer.Start();             
于 2013-02-12T21:56:42.737 回答