zoukankan      html  css  js  c++  java
  • 线程内打开窗体

    最近做了个线程,想在线程中打开窗体,结果总是一闪就木有了。在忘了看了下,原来是线程结束后会回收资源。把打开行窗体的资源回收了。

    所以在要加点东东:

    1. private void Form1_Load(object sender, EventArgs e)  
    2.         {  
    3.             int threadId = Thread.CurrentThread.ManagedThreadId;  
    4.             textBox1.Text = threadId.ToString(); //将主线程ID显示在文本框中  
    5.         }  
    6.   
    7.         private void button1_Click(object sender, EventArgs e)  
    8.         {  
    9.             Thread thread2 = new Thread(threadPro);//创建新线程  
    10.             thread2.Start();  
    11.         }  
    12.         public void threadPro()  
    13.         {  
    14.             textBox2.Text = Thread.CurrentThread.ManagedThreadId.ToString();  
    15.              MethodInvoker MethInvo = new MethodInvoker(ShowForm2);  
    16.              BeginInvoke(MethInvo);  
    17.         }  
    18.         public void ShowForm2()  
    19.         {  
    20.             Form2 f2 = new Form2();  
    21.             f2.Show();  
    22.         } 
  • 相关阅读:
    bzoj3786 星系探索
    [JSOI2008]火星人
    [NOI2005]维护数列
    [POI2008]砖块Klo
    郁闷的出纳员
    [HNOI2002]营业额统计
    [BZOJ1651][Usaco2006 Feb]Stall Reservations 专用牛棚
    [BZOJ2124]等差子序列
    [BZOJ3038]上帝造题的七分钟2
    [BZOJ1711][Usaco2007 Open]Dining吃饭
  • 原文地址:https://www.cnblogs.com/shootingstar/p/3656620.html
Copyright © 2011-2022 走看看