C# Outlook处理应用程序
我使用Windows窗体并使用C# Outlook处理应用程序,c#,winforms,interop,C#,Winforms,Interop,我使用Windows窗体并使用Interop库执行Outlook应用程序,如下所示: Outlook.Application outlookApp = new Outlook.Application(); Outlook.MailItem mailMessage = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem); mailMessage.Subject = "test@m
Interop
库执行Outlook应用程序,如下所示:
Outlook.Application outlookApp = new Outlook.Application();
Outlook.MailItem mailMessage = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
mailMessage.Subject = "test@mail.us";
mailMessage.HTMLBody = "test";
mailMessage.Display(true);
要执行Outlook,我使用mailMessage.Display(true)代码>,但当我使用它时,我无法再使用我的应用程序,我的应用程序只是冻结了,但当我关闭Outlook应用程序时,它会再次工作。如何将outlook作为应用程序的依赖项处理,以便同时使用我的应用程序和outlook?。问候1。创建后台工作人员
通过“组件”下的“工具箱”添加backgroundWorker实例,从而创建backgroundWorker实例
2.以构造函数的形式
将新添加的backgroundWorker实例放置在form类的构造函数中:
public Form1()
{
InitializeComponent();
outlookWorker.DoWork += new DoWorkEventHandler(outlookWorker_DoWork);
}
3.运行异步
通过backgroundWorker实例在button_click事件中为应该打开outlook窗口的按钮添加RunWorkerAsync方法:
private void button1_Click(object sender, EventArgs e)
{
outlookWorker.RunWorkerAsync();
}
4.打开outlook窗口
添加先前编写的代码,以将outlook窗口实例化为backgroundWorker的DoWork事件:
private void outlookWorker_DoWork(object sender, DoWorkEventArgs e)
{
Outlook.Application outlookApp = new Outlook.Application();
Outlook.MailItem mailMessage = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
mailMessage.Subject = "test@mail.us";
mailMessage.HTMLBody = "test";
mailMessage.Display(true);
}
现在,在打开outlook窗口后,您可以按任意按钮或对窗体执行辅助操作
我希望这有助于你实现你的目标
来源