简体   繁体   English

从Windows Service启动C#Microsoft.Office.Interop.Outlook

[英]C# Microsoft.Office.Interop.Outlook launch from Windows Service

I'm using the Microsoft.Office.Interop.Outlook to do the following:- 我正在使用Microsoft.Office.Interop.Outlook执行以下操作:

  1. Read an Outlook folder called 'Pending' 读取一个名为“待处理”的Outlook文件夹
  2. Get the attachment from all emails under 'Pending' folder 从“待处理”文件夹下的所有电子邮件中获取附件
  3. Save the attachment to hard disk folder 将附件保存到硬盘文件夹
  4. Read the attachment from the saved file and upload to our data base 从保存的文件中读取附件并上传到我们的数据库

All the above points are working perfectly fine if I run my C# console application manually. 如果我手动运行C#控制台应用程序,以上所有这些都可以正常工作。 It also works sometimes when I launch the console application from Windows Service. 当我从Windows Service启动控制台应用程序时,有时也可以使用。 But some times not. 但是有时候没有。 I read somewhere in Stack that Microsoft.Office.Interop.Outlook is not designed for Windows Services. 我在Stack的某个地方读到Microsoft.Office.Interop.Outlook不是为Windows Services设计的。

What is the best method (quick and fast to develop) to all the above task from Windows Service? 通过Windows Service完成上述所有任务的最佳方法(快速,快速开发)是什么?

What is the best method (quick and fast to develop) to all the above task from Windows Service ? 从Windows Service完成上述所有任务的最佳方法(快速,快速开发)是什么?

Short answer - you can't. 简短答案- 您不能。

COM Automation servers such as the ones from Microsoft Office are GUI-based and therefore require a message pump . COM Automation服务器(例如Microsoft Office的服务器)是基于GUI的,因此需要消息泵 When you consider that Windows Services typically run prior to a user logging in, it's not possible to launch a process that attempts to show a GUI. 如果您认为Windows服务通常用户登录之前运行,则无法启动尝试显示GUI的进程。 It would simply lock-up. 它只会锁定。

One could argue that you could always wait until the user logs into Windows but then it sort of defeats the purpose of windows services - that user login is not necessary. 有人可能会争辩说,您总是可以等到用户登录Windows时,才可能违反Windows服务的目的-不需要用户登录。 Plus if Windows were to reboot your app would not run until the user logs in again. 另外,如果Windows要重新启动,您的应用程序将在用户再次登录后才能运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在使用 Microsoft.Office.Interop.Outlook 从 C# 发送邮件时删除“代表” - How to remove "on behalf of " while sending mail from C# using Microsoft.Office.Interop.Outlook Microsoft.Office.Interop.Outlook - Microsoft.Office.Interop.Outlook 使用Microsoft.Office.Interop.Outlook连接到Outlook的稳定性C#表单 - Stability C# Forms connected to Outlook using Microsoft.Office.Interop.Outlook Outlook API或使用Microsoft.Office.Interop.Outlook-在C#中获取会议室/位置 - Outlook APIs OR Using Microsoft.Office.Interop.Outlook - Getting meeting room/location in C# 使用 Microsoft.Office.Interop.Outlook C# 在客户端打开 Outlook 2013 新约会窗口 - Open Outlook 2013 New Appointment window at Client side with Microsoft.Office.Interop.Outlook C# 从 MailItem (Microsoft.Office.Interop.Outlook) 获取唯一 ID? - Get Unique Id From MailItem (Microsoft.Office.Interop.Outlook)? 如何使用Microsoft.Office.Interop.Outlook库通过C#读取.eml文件? - How Can I use Microsoft.Office.Interop.Outlook library to read .eml file using C#? C#,Microsoft.Office.Interop.Outlook,非默认文件夹 - c#, Microsoft.Office.Interop.Outlook, non default-folder Microsoft.Office.Interop.Outlook发布内存 - Microsoft.Office.Interop.Outlook Release Memory Microsoft.Office.Interop.Outlook GetFolderFromID - Microsoft.Office.Interop.Outlook GetFolderFromID
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM