![](/img/trans.png)
[英]Are there better ways for updating an execution timer every second than using a background worker that checks every 150 ms?
[英]Background Timer every second, is this the right way?
我想每秒鍾跑一個計時器。 但是我不想在UI線程上運行它,以防止凍結。
因此,我使用的不是Designer提供的內置計時器。 而且我不太確定這是否是正確的方法。
threadtimer = new System.Threading.Timer(timer, null, 1000, Timeout.Infinite);
private void timer(object obj)
{
dowork.....
threadtimer.Change(1000, Timeout.Infinite);
}
這似乎是錯誤的,我首先創建線程,並告訴它在無限時間內運行1000次。 而且我仍然必須重述才能永遠做到這一點。 如果第二個參數不成立,為什么還要第二個參數呢?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.