首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Windows中使用DispatcherTimer

在Windows中使用DispatcherTimer
EN

Stack Overflow用户
提问于 2012-09-16 18:27:20
回答 1查看 2.3K关注 0票数 4

为什么我的DispatcherTimer不使用Windows。

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

代码语言:javascript
复制
    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 ...");
    }
EN

回答 1

Stack Overflow用户

发布于 2012-09-16 18:32:13

DispatcherTimer的目的是在dispatcher线程上触发它的Tick事件。这一点很重要,因为您只能在dispatcher线程上操作Silverlight/WPF UI元素。在Windows服务中,没有调度程序线程.没有可操作的UI。为什么要使用DispatcherTimer而不是(比方说) System.Timers.Timer

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12449503

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档