小编Shr*_*oom的帖子

无法在 Outlook 运行时获取 Outlook.Application,直到非 Outlook 窗口位于前台

Marshal.GetActiveObject("Outlook.Application")Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))在 Outlook 启动时引发并在运行时继续,直到非 Outlook 窗口成为活动的前景窗口。

我在 Windows 10 Version 1803 Build 17134.523(这是我的本地机器)上运行 Outlook Version 1901 Build 11231.20130。我观察到不以这种方式运行的客户端机器。这发生在使用 .NET 4.5.2 和 Microsoft.Office.Interop.Outlook 版本 15.0.4797.1003 通过 NuGet 获得的 WPF 应用程序中。

我反复运行以下代码。如上所述,一旦最小化 Outlook 实例或将非 Outlook 窗口设置为前台,它就会成功,但在发生这种情况之前,它可能会持续失败(下面的输出)。我试图暂停约 20-30 秒,让 Outlook 有时间加载,但仍然得到相同的结果。

    // Detect that the active window is an Outlook window
    Outlook.Application app = null;
    // Optional: Wait for Outlook to load 20-30 sec using Thread.Sleep
    try
    {
        Debug.WriteLine("app");
        app = (Outlook.Application)Marshal.GetActiveObject("Outlook.Application");
        Debug.WriteLine("got app");
    }
    catch …
Run Code Online (Sandbox Code Playgroud)

.net c# outlook com-interop office-interop

6
推荐指数
1
解决办法
293
查看次数

标签 统计

.net ×1

c# ×1

com-interop ×1

office-interop ×1

outlook ×1