Outlook 2010 Com addin - NewExplorer never works

For some reason, in my application, my FolderSwitch works with the main explorer that the application opens, but the NewExplorer event never fires, so obviously the FolderSwitch event will not fire in the new explorer.

I can not understand why the event is not triggered.

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); } 
+4
source share
1 answer

For any events that you want to observe when using VSTO, you need to support a class element ( Explorer , Application , Inspector , CommandBar , etc.) to save the GC Stream from deleting them. This is resource optimization, but it can also be a painful lesson to learn.

See the related MSDN Forum post for a lifetime or similar SO post .

+5
source

Source: https://habr.com/ru/post/1399428/


All Articles