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

查看:21
本文介绍了使用哪个 .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?

谢谢.

推荐答案

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

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天全站免登陆