我正在为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秒钟。
有可能以某种方式做到这一点?
提前谢谢!
答案 0 :(得分: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();