110,536
社区成员
发帖
与我相关
我的任务
分享
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public delegate void InvokeMethodDelegate(string name);
private void button1_Click(object sender, EventArgs e)
{
DoWithCommon();
}
private void DoWithCommon()
{
WaitCallback waitCallBack = new WaitCallback(this.InvokeMethod);
ThreadPool.QueueUserWorkItem(waitCallBack, "Knights Warrior");
}
private void InvokeMethod(object x)
{
this.Invoke(new InvokeMethodDelegate(this.ChangeUIWithCommon), x.ToString());
}
private void ChangeUIWithCommon(string name)
{
this.button1.Text = name;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
//在InvokeMethod运行过程中,关闭窗体,如何才能释放该连接呢
}
}
private void InvokeMethod(object x)
{
if (this.IsDisposed) return;
this.Invoke(new InvokeMethodDelegate(this.ChangeUIWithCommon), x.ToString());
}