C# 带windows服务的outlook

C# 带windows服务的outlook,c#,outlook,windows-services,C#,Outlook,Windows Services,为了访问outlook日历,我创建了一个windows服务 public SOutlook() { InitializeComponent(); if (!System.Diagnostics.EventLog.SourceExists("MyLogSrc")) { System.Diagnostics.EventLog.CreateEventSource("MyLogSrc", "MyLog");

为了访问outlook日历,我创建了一个windows服务

public SOutlook()
    {
        InitializeComponent();

        if (!System.Diagnostics.EventLog.SourceExists("MyLogSrc"))
        {
            System.Diagnostics.EventLog.CreateEventSource("MyLogSrc", "MyLog");
        }

        //set our event log to system created log
        myEventLog.Source = "MyLogSrc";
        myEventLog.Log = "MyLog";

        tmrDelay = new System.Timers.Timer(5000);
        tmrDelay.Elapsed += new System.Timers.ElapsedEventHandler(tmrDelay_Elapsed);
    }

 void tmrDelay_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {

        GetAllCalendarItems();
    }
GatAllCalenderItems()是一个fct,它访问outlook日历,获取所需信息,然后将所有信息保存在数据库中。我已经测试过了,它工作正常(计时器也工作)。由于某些原因,此功能在windows服务中不起作用

protected override void OnStart(string[] args)
    {
        myEventLog.WriteEntry("MyService started");
        tmrDelay.Enabled = true;
    }

有人能帮我一下吗

到底什么不起作用?Outlook(或任何其他Office应用程序)无法在服务中使用。

一个问题可能是您的服务所使用的帐户。您还应该在
GetAllCalendarItems
中包含代码。当您说“它不工作”时,它是否会引发异常,或者只是不将任何内容保存到您的数据库中。在GetAllCalendarItems()中,它只会访问部分var oCalenderFolder=oNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);var-outlookCalendarItems=oCalenderFolder.Items;是的,它不会在数据库中保存任何内容。。即使它在windows窗体中工作正常,服务在哪个帐户下运行?你是指用户吗?我的用户是管理员,如果这是您的意思,则无法使Outlook在服务中工作?否CDO 1.21(Outlook、Extended MAPI(仅限C++或Delphi)或Redemption(任何语言)不再支持或安装)可以在服务中使用。Outlook对象模型不能。好的,thx,我不知道什么是赎回,但我会研究它。您能告诉我如何使用赎回来访问Outlook日历吗?使用RDO对象系列().RDOSession对象大致对应于Outlook对象模型中的命名空间对象。要获取日历文件夹,请调用RDOSession.GetDefaultFolder(olFolderCalendar)。