簡體   English   中英

加載 Outlook 后如何在 VSTO 插件上執行事件 C#

[英]How to Execute Event on VSTO Add In Once Outlook is loaded C#

如何在 Outlook 應用程序完全加載后執行事件。 我試圖在 C# VSTO 插件啟動事件觸發時執行一些代碼,但我希望在應用程序完成加載后運行腳本。 有什么想法嗎?

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {

        //Doesn't make sense to add script here because outlook is still not finished loading
    }

    private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
    {
        // Note: Outlook no longer raises this event. If you have code that 
        //    must run when Outlook shuts down, see http://go.microsoft.com/fwlink/?LinkId=506785
    }

    #region VSTO generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InternalStartup()
    {
        this.Startup += new System.EventHandler(ThisAddIn_Startup);
        this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);

    }

    #endregion
}

Application 類的Startup事件在 Microsoft Outlook 啟動時觸發,但在所有加載項都已加載之后。

為了后代,我每天都使用堆棧,但從未發布過。 我為 Visio 維護了一個 VSTO 加載項,它與其他 Office 加載項具有共同的相關性...

我也試圖在加載項啟動事件中運行代碼:ThisAddIn_Startup。

this.Application.ActiveDocument.DocumentChanged += MyEventHandler;

我不斷收到異常:值不能為空。 參數名稱:o

我發現,雖然加載了加載項,但沒有打開的文檔: this.Application.ActiveDocument 為空

我將事件處理程序分配更改為: this.Application.DocumentOpened += MyHigherLayerEventHandler;

參考: https : //docs.microsoft.com/en-us/visualstudio/vsto/programming-vsto-add-ins ? view = vs- 2019# AccessingDocuments https://docs.microsoft.com/en-us/visualstudio /vsto/events-in-office-projects?view=vs-2019 https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.tools.addinbase.requestcomaddinautomationservice?view=vsto-2017 https ://docs.microsoft.com/en-us/visualstudio/vsto/architecture-of-vsto-add-ins?view=vs-2019

然后——(這部分可能需要在一個單獨的主題中,idk,但是)我注意到該事件被觸發了兩次。 事實上, ThisAddIn_Startup --and-- ThisAddIn_Shutdown 都觸發了 2 次。 這個周末我花了大約 10 個小時試圖解決這個問題。 我什至添加了一個帶有消息框的增量計數器:消息框彈出 2 次並且計數器沒有增加。

問題/解決方案原來是注冊表項。 如果您像我這樣的開發人員,您的機器可能有多個測試項目,也許還有一些廢棄的舊項目。 我有一個具有相同清單文件名但存儲庫位置不同的舊加載項。 在通過注冊表進行幾次查找搜索后

Computer\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Visio\\Addins\\TEAM_VSTO <-- 我刪除了這個注冊表項

計算機\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Visio\\Addins\\NewAddinName

*presto、magic、event 僅觸發 1 次 *facepalm 無論如何,我希望這對某人有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM