当前位置: 动力学知识库 > 问答 > 编程问答 >

.net - C# repeat button action

问题描述:

I'm developing an app for a RFID reader. I have a button with the following action:

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

}

}

}

What I want is the reading of the label to repeat every 2 seconds instead of displaying the MessageBox.Show("The label couldn't be read!");.

For the other case, when a label it's read I want this process to stop for let's say 20 seconds and after 20 seconds to start reading again at avery 2 seconds.

It is possible to do that somehow?

Thank you in advance!

网友答案:

Have you looked into timer control?

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();             
分享给朋友:
您可能感兴趣的文章:
随机阅读: