2011-03-18 49 views
2

所以,我有這個簡單的控制檯應用程序:在.Net 2.0的另一個線程中加載表單?

using System; 
using System.Collections.Generic; 
using System.Text; 
using System.Threading; 
using FormLoader; 

namespace FormLoaderTest 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      FormLoaderClass.Load(); 

      while (true) 
      { 
       Console.Write("."); 
       Thread.Sleep(17); 
      } 
     } 
    } 
} 

這是FormLoaderClass類:

using System; 
using System.Collections.Generic; 
using System.Text; 
using System.Drawing; 
using System.Windows.Forms; 
using System.Threading; 

namespace FormLoader 
{ 
    public class FormLoaderClass 
    { 
     public void Load() 
     { 
      new ModLoaderWindow().Show(); 
     } 
    } 
} 

第二個項目是從控制檯應用程序引用另一個DLL。我的問題是窗體顯示,但凍結,而控制檯應用程序愉快地寫點到控制檯窗口。

我該怎麼做,控制檯窗口將繼續寫點,並且用戶與窗體的交互仍然是可能的?我正在考慮一些線程,但那並不是真的。它只是在第一次繪製時才顯示該形式,或者它保持冷凍。

回答

4

它會因爲表單需要消息隊列而凍結 - 這就是Application.Run(Form f)的用途。但是,這個調用是阻塞的,所以你肯定需要第二個線程來運行它。

相關問題