下面是一些示例代码:
private Outlook.Application applicationObject;
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
{
MessageBox.Show("on connection");
applicationObject = (Outlook.Application)application;
applicationObject.Explorers.NewExplorer += new Microsoft.Office.Interop.Outlook.ExplorersEvents_NewExplorerEventHandler(Explorers_NewExplorer);
}
void Explorers_NewExplorer(Microsoft.Office.Interop.Outlook.Explorer Explorer)
{
MessageBox.Show("new explorer");
}"new explorer“消息从来不会出现在屏幕上,因为NewExplorer事件从来不会触发,甚至当我点击”在新窗口中打开“时也不会。
会出什么问题呢?
发布于 2012-11-23 09:30:21
订阅NewExplorer事件的Explorers实例可能会被垃圾回收。要防止这种情况发生,请通过实例变量保留对它的引用:
private Outlook.Application applicationObject;
private Outlook.Explorers explorers;
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
{
MessageBox.Show("on connection");
applicationObject = (Outlook.Application)application;
explorers = applicationObject.Explorers;
explorers.NewExplorer += new Microsoft.Office.Interop.Outlook.ExplorersEvents_NewExplorerEventHandler(Explorers_NewExplorer);
}https://stackoverflow.com/questions/13521950
复制相似问题