简体   繁体   中英

C# Microsoft.Office.Interop.Outlook launch from Windows Service

I'm using the Microsoft.Office.Interop.Outlook to do the following:-

  1. Read an Outlook folder called 'Pending'
  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. It also works sometimes when I launch the console application from Windows Service. But some times not. I read somewhere in Stack that Microsoft.Office.Interop.Outlook is not designed for Windows Services.

What is the best method (quick and fast to develop) to all the above task from Windows Service?

What is the best method (quick and fast to develop) to all the above task from 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 . 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. 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. Plus if Windows were to reboot your app would not run until the user logs in again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM