C# 将Dispatchermer与Windows服务一起使用

C# 将Dispatchermer与Windows服务一起使用,c#,windows-services,dispatcher,C#,Windows Services,Dispatcher,为什么我的Dispatcher不能与Windows服务一起工作 我希望使用Dispatchermer检查windows服务许可证的目的 public OIMService() { InitializeComponent(); _dispatcherTimer = new DispatcherTimer(); if (!System.Diagnostics.EventLog.SourceExists("OIM_Log"))

为什么我的Dispatcher不能与Windows服务一起工作

我希望使用Dispatchermer检查windows服务许可证的目的

    public OIMService()
    {
        InitializeComponent();
        _dispatcherTimer = new DispatcherTimer();
        if (!System.Diagnostics.EventLog.SourceExists("OIM_Log"))
        {
            EventLog.CreateEventSource("OIM_Log", "OIMLog");
        }
        EventLog.Source = "OIM_Log";
        EventLog.Log = "OIMLog";
        _helpers = new ValidationHelpers();
        StartTimer();

    }


protected override void OnStart(string[] args)
{
    System.Diagnostics.Debugger.Launch();

    if (_helpers.IsValid())
    {
        ConfigureServer();
        StartTimer();
    }
    else
    {
        this.Stop();
    }


}



 private void StartTimer()
        {
            const int time = 10;
            _dispatcherTimer.Tick += new EventHandler(DispatcherTimerTick);
            _dispatcherTimer.Interval = new TimeSpan(0, 0, Convert.ToInt32(time));
            _dispatcherTimer.IsEnabled = true;
            _dispatcherTimer.Start();
        }
    private void DispatcherTimerTick(object sender, EventArgs e)
    {

        EventLog.WriteEntry("test test test ...");
    }

dispatchermer
的要点是在dispatcher线程上触发其
Tick
事件。这很重要,因为您只能在dispatcher线程上操作Silverlight/WPF UI元素。在Windows服务中,没有调度程序线程。。。没有可操作的UI。为什么您要使用
Dispatchermer
而不是(比如)?

我想使用Dispatchermer检查windows服务许可证day@tito11:当您没有UI时,为什么您认为Dispatcher是最适合使用的计时器?