private void button1_Click(object sender, EventArgs e)
{
Form7 form7 = new Form7();
form7.ShowDialog();
System.Threading.Thread.Sleep(2000);
form7.Close();
}
private void button1_Click(object sender, EventArgs e)
{
Form7 form7 = new Form7();
form7.Show();
System.Threading.Thread.Sleep(2000);
form7.Close();
}
using System.Windows.Forms;
namespace test
{
public partial class Form7 : Form
{
public Form7()
{
InitializeComponent();
}
}
}
显示
TProcess = Task.Factory.StartNew(() =>
{
form7= new Form7();
form7.ShowDialog();
});
关闭
this.Invoke(new Action(() =>
{
if (form7!= null)
{
form7.Close();
form7.Dispose();
form7= null;
}
}));
用线程跑这个form对吧
@echo_lovely: 对
new Thread(()=>{Tread.Sleep(2000);wnd.Invoke(()=>{wnd.Close();});}).Start();
进度条同理;防止 重复执行,可以加个lock,如:
Monitor.TryEnter(__Lock,out canRun);
if(!canRun)return;
new Thread(()=>{Tread.Sleep(2000);wnd.Invoke(()=>wnd.Close();});Monitor.Release(__Lock);}).Start();
慢慢理解界面线程,多线程。
可以用用Task或BackgroundWorker来实现