2008-10-25 73 views
1

我在Visual Studio 2005中創建一個簡單的.NET Windows應用程序,並在剛進入的主要形式加載事件我線程窗口,如下圖所示:解釋Visual Studio 2005的線程窗口

http://img519.imageshack.us/my.php?image=threadshh4.jpg

我問題是

1)爲什麼在首位這麼多線程的時候我還沒有從我的應用程序的「主線」)

2)這是什麼的線程命名爲」淨SystemEvents開始任何(除'呢?

3)爲什麼除了主線程以外的所有線程的'位置'列下的條目爲空?

編輯:
4)是否有可能使這些線程無法啓動?或過一段時間後離開?
5)他們打算做什麼?他們的目的是什麼?

回答

3

1)它們是被管理框架的一部分。

2)它監視系統事件,您可以註冊事件處理程序,例如當您更改顯示設置等。

3)因爲它們是框架的一部分而不是應用程序代碼,所以調試器不知道源位置。

0

請記住,非託管線程和託管線程之間存在一對多的關係。

還有就是要通知移動SystemEvents到你的線程的方式:

public static class ThreadingHelper_NativeMethods 
{ 
    [DllImport("user32.dll")] 
    public static extern bool IsGUIThread(bool bConvert); 
} 


    // This code forces initialization of .NET BroadcastEventWindow to the UI thread. 
    // http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/fb267827-1765-4bd9-ae2f-0abbd5a2ae22 
    if (ThreadingHelper_NativeMethods.IsGUIThread(false)) 
    { 
     Microsoft.Win32.SystemEvents.InvokeOnEventsThread(new MethodInvoker(delegate() 
     { 
      int x = 0; 
     })); 
    }