Timer.Tick将不会启动新的EventHandler

时间:2019-05-08 09:35:36

标签: c# .net timer progress-bar

我已经有了这个计时器,它将计时10秒。我想要一个进度条来显示它,需要多长时间等,现在可能是10秒,但将来可能是动态的。

private void button1_Click_1(object sender, EventArgs e)
{
    dataGridView1.DataSource = null;
    labelCapture.Text = " ";
    buttonCapture.Enabled = false;
    labelCapture.Text = "Measuring for 10 seconds...";
    timerCapture.Interval = 10000;
    timerCapture.Enabled = true;
    UseWaitCursor = true;
    timerCapture.Start();

    Program.ModalForm.progressBarFormModal.Maximum = 10;
    timerCapture.Tick += new EventHandler(timerCapture_Tick);

    capture = true;

    myFormModal.ShowDialog(this); // Where I open the ModalForm
}

我的活动如下

void timerCapture_Tick(object sender, EventArgs e)
{
    if (Program.ModalForm.progressBarFormModal.Value != 10)
    {
        Program.ModalForm.progressBarFormModal.Value++;
    }
    else
    {
        timerCapture.Stop(); 
    }
}

模态表单如何关闭

    private void TickToggle(object sender, EventArgs e)
    {
        capture = false;
        timerCapture.Stop();
        UseWaitCursor = false;
        timerCapture.Enabled = false;

        myFormModal.Close(); // Close the modal form after timer is done
    }

有人看到我可能忽略的错误了吗?

0 个答案:

没有答案