public delegate void DelegateShow(string msg);
public DelegateShow OnMiao;
private void Threads_Load(object sender, EventArgs e)
{
OnMiao += new DelegateShow(Add_OnLog);
}
void Add_OnLog(string msg)
{
Action<string> action = new Action<string>(textBox1.AppendText);
textBox1.Invoke(action, string.Format("【{0}】:{1}\n", DateTime.Now.ToString(), msg));
}
private void button1_Click(object sender, EventArgs e)
{
this.button1.Enabled = false;
Action _a = null;
_a = () => _aaaa();
_a.BeginInvoke(null, null);
this.button1.Enabled = true;
} void _aaaa()
{
for (int i = 0; i < 5; i++)
{
Thread.Sleep(1000);
Add_OnLog("提示1秒");
}
}
代码如上,我想控制Button的Enabled属性,在执行完5秒后才能使用。
现在的问题是,因为是异步执行的,所以当我点了之后,马上就又能使用了。
请高手指点指点,谢谢啦
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货