难道C#定时器经过一个单独的线程? [英] Do C# Timers elapse on a separate thread?

查看:285
本文介绍了难道C#定时器经过一个单独的线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

做了System.Timers.Timer经过比创建它的线程一个单独的线程?

Does a System.Timers.Timer elapse on a separate thread than the thread that created it?

可以说我有一类与每5秒触发一个计时器。当计时器火灾,在经过的方法,有些对象被修改。可以说,这需要很长的时间来修改这个对象,像10秒。是否有可能,我会在这种情况下碰上线程冲突?

Lets say I have a class with a timer that fires every 5 seconds. When the timer fires, in the elapsed method, some object is modified. Lets say it takes a long time to modify this object, like 10 seconds. Is it possible that I will run into thread collisions in this scenario?

推荐答案

有关的 System.Timers.Timer

For System.Timers.Timer:

请参见下面

System.Threading.Timer :

For System.Threading.Timer:

关于定时器状态MSDN文档:

该System.Threading.Timer类的品牌
  在一个线程池线程回调

  在所有不使用事件模型。

The System.Threading.Timer class makes callbacks on a ThreadPool thread and does not use the event model at all.

因此​​,我们确实计时器在不同的线程为止。

So indeed the timer elapses on a different thread.

这篇关于难道C#定时器经过一个单独的线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆