如何在2010 AddIn项目中以编程方式关闭Outlook Outlook?

时间:2014-07-21 10:52:00

标签: c# outlook-addin shutdown

我需要在每天00:00时关闭Outlook。是否有任何方法以编程方式关闭outlook?

感谢您的帮助。

2 个答案:

答案 0 :(得分:3)

享受!

public partial class ThisAddIn
    {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            Thread thread = new Thread(p =>
            {
                DateTime now = DateTime.Now;
                DateTime endOfDay = DateTime.Today.AddDays(1);
                TimeSpan timeLeftForClose = endOfDay.Subtract(now);
                Thread.Sleep(timeLeftForClose);
                this.Application.Quit();                    
            });
            thread.Start();
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }


        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }


    }

答案 1 :(得分:2)

Outlook.Application OutlookApp;
OutlookApp = (Outlook.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Outlook.Application");
OutlookApp.Quit()