问题标签 [timer]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
1559 浏览

c# - 有谁知道 System.Windows.Forms.Timer 通常如何影响主机应用程序和系统?

有谁知道 aSystem.Windows.Forms.Timer一般如何影响主机应用程序和系统?

一方面,线程化的后台循环具有非常高的 CPU 使用率,而Timer具有非常高的滴答率的循环在 Windows 任务管理器中没有任何效果。

高滴答率计时器是否会使 Windows 消息循环混乱,或者?

0 投票
1 回答
965 浏览

java - 在具有两个计时器的类中,它们是否在两个单独的线程中执行?

在 java 类中,我有两个计时器

作为两个单独的线程执行和t1执行?t2你如何验证它?

0 投票
7 回答
3462 浏览

java - Java Timer class says "Timer tasks should complete quickly" , how do we define quickly?

I am planning to use this to poll a database which can take close to 10-15 minutes or more, so should I be using timers for this.

0 投票
10 回答
415427 浏览

java - System.currentTimeMillis vs System.nanoTime

准确性对比 精确

我想知道的是在我的游戏中更新对象的位置时是否应该使用System.currentTimeMillis()System.nanoTime() ?他们的运动变化与自上次通话以来经过的时间成正比,我希望尽可能精确。

我读过不同操作系统之间存在一些严重的时间分辨率问题(即 Mac / Linux 的分辨率几乎为 1 毫秒,而 Windows 的分辨率为 50 毫秒??)。我主要在 Windows 上运行我的应用程序,50 毫秒的分辨率似乎非常不准确。

有比我列出的两个更好的选择吗?

有什么建议/意见吗?

0 投票
3 回答
859 浏览

.net - Proper way to get a Winforms UI to block with a dialog until some non-user driven event conditioin?

I was asking about specifics with this approach earlier today here but the confused responses has me wondering if I'm going about this all wrong.

So here's the problem. I need to architect a WinForms application that periodically checks a value from some external service. If it is in a certain state the application is supposed to pop up a modal form blocking the user from interacting with the application until such time that the state changes. The blocked UI should act just like when a form is displayed using ShowDialog(). That is to say the user should not be able to interact with the ui in any way until the dialog is closed (in this case this can only be done by the application).

In my particular application I have the requirement crop up in several instances. For example, at one point the application runs a timer that repeatedly checks the value of a cell in a db table that is constantly being updated by a weighing device. If the value is below a certain threshold the user is prompted to place items on the scale - he or she may not proceed nor interact with the UI until they do so.

Every solution I have tried has been chock full of threading problems. Either the dialog won't block the UI, or the timer will not continue checking the external service or the application cannot close the form when the time comes.

This seems like a fairly standard winforms requirement and there must be a relevant design pattern that does not bring in Windows.Forms.Timer (I like keep it my views passive). How would you do this?

0 投票
6 回答
656125 浏览

python - 如何让我的 Python 程序休眠 50 毫秒?

如何让我的 Python 程序休眠 50 毫秒?

0 投票
2 回答
326 浏览

.net - 当我的主要方法在 Windows 服务中运行时,我是否应该让计时器进入睡眠状态

在我的 .net windows 服务中,当我的计时器过去并且我的主要方法被调用时,将计时器置于睡眠模式是最佳做法吗?

这是为了以防我的 main 方法运行时间过长,并且在之前的调用 main 方法完成执行之前计时器已经过去。

0 投票
6 回答
69716 浏览

c# - 比较使用 Thread.Sleep 和 Timer 来延迟执行

我有一个方法应该延迟运行指定的时间。

我应该使用

或者

我读过一些关于使用Thread.Sleep是糟糕的设计的文章。但我真的不明白为什么。

但是对于使用 Timer,Timer 有 dispose 方法。由于执行延迟,我不知道如何处置 Timer。你有什么建议吗?

或者,如果您有延迟执行的替代代码,也很感激。

0 投票
7 回答
12968 浏览

c# - 带有计时器的 .NET Windows 服务停止响应

我有一个用 C# 编写的 Windows 服务。它内部有一个计时器,它会定期触发一些功能。所以我的服务的骨架:

它工作一段时间(如 10-15 天)然后停止。我的意思是服务显示为正在运行,但它没有做任何事情。我做了一些记录,问题可能出在计时器上,因为在间隔之后它不会调用 tickTack_Elapsed 函数。

我正在考虑在没有计时器的情况下重写它,使用无限循环,它会在我设置的时间内停止处理。这也不是一个优雅的解决方案,我认为它可能会对内存产生一些副作用。

Timer 是从 System.Timers 命名空间中使用的,环境是 Windows 2003。我在不同服务器上的两个不同服务中使用了这种方法,但两者都产生了这种行为(这就是为什么我认为它以某种方式连接到我的代码或框架本身)。

有人经历过这种行为吗?有什么问题?


编辑:

我编辑了这两个服务。一个人到处都有很好的尝试捕获和更多的日志记录。第二个定期进行计时器娱乐。自他们以来,他们都没有停止过,所以如果这种情况再持续一周,我将结束这个问题。到目前为止,谢谢大家。


编辑:

我关闭了这个问题,因为什么都没发生。我的意思是我做了一些更改,但是这些更改与这件事并不真正相关,并且从那时起这两个服务都运行没有任何问题。请将其标记为“因不再相关而关闭”。

0 投票
2 回答
2921 浏览

java - EJB 计时器是否应该是持久/可靠的?

例如,如果我将计时器设置为每天午夜到期,如果一个“失火”(例如,由于服务器关闭而不会触发回调)会发生什么?我在文档中找不到。

有没有办法让这个计时器在服务器重启后立即触发回调?

PS:我知道 Quartz,我正在评估 EJB 计时器作为替代方案。