我创建了2个功能,可完成某些特定功能。 我在计时器上调用这些函数。但是在功能1完成之前,功能2开始处理。我怎样才能等到1完成才能开始2。
这是我的代码:
private void btnrun_Click(object sender, EventArgs e)
{
try
{
_bat.ShowDialog();
StrBatchNumber = _bat.GlobalBatchNumber;
DialogResult _diaresult = _bat.DialogResult;
if (_diaresult == DialogResult.OK)
{
if (StrBatchNumber == "")
{
MessageBox.Show("Please enter a batch number", "Batch Number Missing", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
btnstartrobo.PerformClick();
btnautostart.PerformClick();
}
}
}
catch(Exception)
{
}
}
System.Windows.Forms.Timer tmrfirst = new System.Windows.Forms.Timer();
private void btnautostart_Click(object sender, EventArgs e)
{
tmrfirst.Interval = 1000;
tmrfirst.Tick += new EventHandler(tmrfirst_Tick);
tmrfirst.Start();
}
private void tmrfirst_Tick(object sender, EventArgs e)
{
btnchecksignal.PerformClick();
Thread.Sleep(100);
if (textBox8.Text.Contains("+1"))
{
button14.PerformClick();
Thread.Sleep(20);
button42.PerformClick();
Thread.Sleep(300);
btnautostart.PerformClick();
}
}
我尝试在两者之间设置thread.sleep,但是它不起作用。我怎样才能解决这个问题?请帮忙。