首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在此Outlook2007应用程序中,为什么Explorers.NewExplorer事件没有触发?

在此Outlook2007应用程序中,为什么Explorers.NewExplorer事件没有触发?
EN

Stack Overflow用户
提问于 2012-11-23 08:58:29
回答 1查看 396关注 0票数 1

下面是一些示例代码:

代码语言:javascript
复制
    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事件从来不会触发,甚至当我点击”在新窗口中打开“时也不会。

会出什么问题呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-23 09:30:21

订阅NewExplorer事件的Explorers实例可能会被垃圾回收。要防止这种情况发生,请通过实例变量保留对它的引用:

代码语言:javascript
复制
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);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13521950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档