1

这是一些示例代码:

    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");
    }

“新资源管理器”消息永远不会出现在屏幕上,因为 NewExplorer 事件永远不会触发,即使我单击“在新窗口中打开”也是如此。

有什么问题?

4

1 回答 1

1

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

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);
}
于 2012-11-23T01:30:20.683 回答