【发布时间】:2020-07-23 23:00:03
【问题描述】:
我的 C# 程序需要启动 Office Outlook 并获取当前的“正在运行的 Outlook 应用程序”。 为此,我实现了以下简单程序(因此,如果您愿意,可以简单地对其进行测试):
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Runtime.InteropServices;
static void Main(string[] args)
{
Outlook.Application outlookObj = null;
if (Process.GetProcessesByName("OUTLOOK").Count().Equals(0))
{
Process.Start("outlook.exe"); // MY PROGRAM STOPS HERE
}
var process = Process.GetProcessesByName("OUTLOOK").First();
while (!process.HasExited)
{
try
{
outlookObj = (Outlook.Application)Marshal.GetActiveObject("Outlook.Application");
break;
}
catch
{
outlookObj = null;
}
System.Threading.Thread.Sleep(10);
}
string result = (outlookObj== null)? "DOES NOT WORK" : "OK";
Console.WriteLine(result);
Console.ReadLine();
}
我的问题是,一旦 Office Outlook 开始运行,我的 C# 控制台应用程序就无法继续其工作。执行Process.Start("outlook.exe"); 指令后,我必须单击 Visual Studio GUI 以重新启动控制台应用程序,最后在我的控制台应用程序上读取“确定”。
我该如何解决我的问题?
【问题讨论】:
标签: c# .net outlook console-application