使用哪个.Net Timer() [英] Which .Net Timer() to use

查看:79
本文介绍了使用哪个.Net Timer()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VB.Net 2.0中有一个旧版WinForms Mdi应用程序,正在向其中添加功能.其中一项是警告,当当前时间接近指定值(截止日期)时,需要发出警告.我的目的是每小时检查一次时间,直到截止日期还不到一个小时,然后按指定的时间间隔显示警告,直到时间到为止.

I have a legacy WinForms Mdi App in VB.Net 2.0 which I am adding functionality to. One of the additions is a warning which needs to be raised when the current time nears a specified value (a deadline). My intention is to check the time once an hour until there is less than an hour until the deadline, then display warnings at specified intervals until the time's up.

用户需要能够在截止日期之前甚至在该截止日期之后继续使用该应用程序,但是需要定期使他们知道截止日期的临近.

The user needs to be able to continue to use the app up to and even after the deadline, but they need to periodically be made aware of the deadline's proximity.

该应用程序尚未使用System.Threading,目前我对它的了解有限.我确实知道有3种不同的Timer()方法可用:

The app does not use System.Threading yet and my knowledge of it is limited at this time. I do know that there are 3 different Timer() methods available:

  • System.Threading.Timer(),
  • Windows.Forms.Timer()和
  • System.Timers.Timer()

我的问题是,哪种方法最好?我尝试使用线程计时器,但是由于WinForms线程不安全,因此在尝试访问另一个类时遇到运行时错误.值得使类/表单线程安全吗?我完全偏离轨道了吗?

My question is, which is the best way to go with this? I attempted to use the threaded timer, but since WinForms are not thread safe I got a run time error trying to access another class. Is it worth making the class/form thread safe? Am I completely off track?

谢谢.

推荐答案

我只使用Forms计时器.我想我读到它不那么准确,但是听起来您不需要它.

I would just use the Forms timer. I think I read that it's not as accurate, but it sounds like you don't need it to be.

这篇关于使用哪个.Net Timer()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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