首先在窗体上放一个button和一个picturebox
(picturebox visible为false)这个多线程的目的是点击按钮后图片正常的运行,另一线程在睡眠10秒后在执行。
private void button1_Click(object sender, EventArgs e)
{
//开启线程
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(this.Result));
pictureBox1.Visible = true;
button1.Enabled = false;
thread.Start();
}
private void Result()
{
bool ok = this.Do();
this.BeginInvoke(new System.Threading.ThreadStart(delegate()
{
if (ok) MessageBox.Show("成功", "提示");
else MessageBox.Show("失败", "提示");
pictureBox1.Visible = false;
button1.Enabled = true;
}));
}
private bool Do()
{
System.Threading.Thread.Sleep(10000);
return true;
}
顶一下
(0)
0%
踩一下
(0)
0%
- 相关评论
- 我要评论
-