最近做了个线程,想在线程中打开窗体,结果总是一闪就木有了。在忘了看了下,原来是线程结束后会回收资源。把打开行窗体的资源回收了。
所以在要加点东东:
- private void Form1_Load(object sender, EventArgs e)
- {
- int threadId = Thread.CurrentThread.ManagedThreadId;
- textBox1.Text = threadId.ToString();
- }
-
- private void button1_Click(object sender, EventArgs e)
- {
- Thread thread2 = new Thread(threadPro);
- thread2.Start();
- }
- public void threadPro()
- {
- textBox2.Text = Thread.CurrentThread.ManagedThreadId.ToString();
- MethodInvoker MethInvo = new MethodInvoker(ShowForm2);
- BeginInvoke(MethInvo);
- }
- public void ShowForm2()
- {
- Form2 f2 = new Form2();
- f2.Show();
- }
线程内打开窗体,布布扣,bubuko.com
线程内打开窗体
原文:http://www.cnblogs.com/shootingstar/p/3656620.html