我知道当执行Thread.Sleep时,我的GUI上的按钮无法被点击.
有没有其他方法可以延迟我的代码流动但仍然能够点击GUI上的按钮?
例如,在我的代码执行Thread.Sleep(10000)之后立即; 在这10秒钟内我无法点击我的button1事件,无论如何我仍然可以在这10秒内点击我的button1事件?
private void displaydata_event2(object sender, EventArgs e)
{
txt_data.AppendText(in_data + "\n");
string inStr;
inStr = in_data;
//MessageBox.Show(inStr.Length.ToString());
if (inStr.Length == 12)
{
int indexOfSpace = inStr.IndexOf(' ');
string Patient = inStr.Substring(indexOfSpace + 1);
int rx = 0;
int selected = 0;
txtData1.Text = Patient;
rx = Convert.ToInt16(Patient);
selected = Convert.ToInt16(txt_pnorec.Text);
if (rx != selected)
{
MessageBox.Show("Please check patient settings");
}
}
else if (inStr.Length == 24)
{
label2.Text = "Patient is not selected!";
label2.BackColor = Color.Red;
} …Run Code Online (Sandbox Code Playgroud)