难道.NET定时器异步运行? [英] Do .NET Timers Run Asynchronously?
问题描述
我有我的应用程序中使用的Jabber网一个消息方面,(一的 XMPP库。)
I have a messaging aspect of my application using Jabber-net (an XMPP library.)
我想这样做,如果由于某种原因连接到服务器端,是不断尝试每分钟左右进行连接。
What I would like to do, if for some reason the connection to the Server is ended, is keep trying to connect every minute or so.
如果我启动一个定时器等待一段时间,下一个尝试之前,这是否定时器异步运行,所得Tick事件加盟为主线,或者我需要开始自己的线程,并从内部启动定时器在那里?
If I start a Timer to wait for a period of time before the next attempt, does that timer run asynchronously and the resulting Tick event join the main thread, or would I need to start my own thread and start the timer from within there?
推荐答案
您使用的是什么样的计时器?
What kind of timer are you using?
-
System.Windows.Forms.Timer
将在UI线程中执行 -
System.Timers.Timer的
在一个线程池线程执行,除非你指定一个SynchronizingObject的
-
System.Threading.Timer
在一个线程池线程执行其回调
System.Windows.Forms.Timer
will execute in the UI threadSystem.Timers.Timer
executes in a thread-pool thread unless you specify aSynchronizingObject
System.Threading.Timer
executes its callback in a thread-pool thread
在所有的情况下,定时器本身将是异步 - 它不会占用一个线程,直到它触发
In all cases, the timer itself will be asynchronous - it won't "take up" a thread until it fires.
这篇关于难道.NET定时器异步运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!