2013-02-12 64 views
1

我正在开发RFID阅读器应用程序。我有以下动作的按钮:C#重复按钮动作

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秒。 有可能做到这一点? 提前谢谢!

回答

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();