小编Nic*_*Nic的帖子

Thread.Sleep时按钮无法单击

我知道当执行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)

c# delay

5
推荐指数
1
解决办法
868
查看次数

标签 统计

c# ×1

delay ×1