2012-03-02 50 views
4

出於某種原因,在我的應用我FolderSwitch適用於與應用程序,但NewExplorer事件永遠不會觸發打開Explorer主,如此明顯的FolderSwitch事件將不會觸發一個新的瀏覽器。展望2010 COM插件 - NewExplorer永遠不會觸發

我不知道爲什麼事件不會觸發。

private List<_Outlook.Explorer> ListOfExplorerWindows = new List<_Outlook.Explorer> { }; 
private _Outlook.Application Application; 

public void OnConnection(object Application, Extensibility.ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) 
{ 
    this.Application = (_Outlook.Application)Application; 
} 

public void OnStartupComplete(ref Array custom) 
{ 
    _Outlook.Explorer Explorer = this.Application.ActiveExplorer(); 
    Explorer.FolderSwitch += new _Outlook.ExplorerEvents_10_FolderSwitchEventHandler(Explorer_FolderSwitch); 
    ListOfExplorerWindows.Add(Explorer); 

    this.Application.Explorers.NewExplorer += new _Outlook.ExplorersEvents_NewExplorerEventHandler(Explorers_NewExplorer); 
} 

private void Explorers_NewExplorer(_Outlook.Explorer Explorer) 
{ 
    Explorer.FolderSwitch += new _Outlook.ExplorerEvents_10_FolderSwitchEventHandler(Explorer_FolderSwitch); 
    ListOfExplorerWindows.Add(Explorer); 
} 
+0

其實,我可能會通過增加 私人_Outlook.Explorers探險固定它; 在課堂上的水平,但我想 私人_Outlook.Application應用程序; 會保持在範圍內,任何人都可以解釋嗎? – Matt 2012-03-02 17:35:49

+0

我自己的信息:你在哪裏綁定到OnConnection和OnStartupComplete?什麼對象有這些事件? – 2015-09-20 16:05:23

+0

我不認爲他們的活動,他們是IExtensibility2 – Matt 2015-09-21 08:57:02

回答

5

對於要使用VSTO時保持周圍的任何事件,你需要保持周圍類級別成員(ExplorerApplicationInspectorCommandBar)保持GC線程刪除它們。這是資源優化,但也可能是一個痛苦的教訓。

查看相關MSDN Forum post regarding event lifetimesimilar SO post

+0

是的,但是我有接口的公共方法「私人_Outlook.Application應用;」這是Application的類對象,但這似乎還不夠,這就是我不明白的地方。即使應用程序在Class級別聲明,我的Application.Explorers是否仍被GC收集? – Matt 2012-03-05 10:58:27

+1

好吧,只需閱讀SO帖子,這有點道理。 – Matt 2012-03-05 11:00:23

相關問題