如何在处理中包括时间? [英] How to include time on the processing?

查看:59
本文介绍了如何在处理中包括时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在列表框中显示行,其中包含通过USB控制物理设备的代码.我想在两行之间有一个处理时间.例如在处理第一行时,应仅在1秒后处理第二行,依此类推.
我怎样才能做到这一点?预先感谢.

My application displays rows in a listbox, which contains code that controls a physical device via USB. I want to have a processing time between the lines. Such as when the first row is processed, the second should be processed only after 1 second, and so on.
How can I do this? Thanks in advance.

推荐答案

为此目的使用单独的线程并使用System.DateTime.Now动态计算询问当前时间的行之间的睡眠时间,并计算要花费多少时间.睡眠并使用System.Threading.Thread.Sleep.

或者,使用(叹息…)计时器.计时器似乎更易于使用,但实际上很难可靠地使用它. .NET中有三个计时器:

System.Threading.Timer;请参阅 http://msdn.microsoft.com/en-us/library/system.threading .timer.aspx [ ^ ];

System.Timers.Timer;请参阅 http://msdn.microsoft.com/en-us/library/system.timers .timer.aspx [ ^ ];

System.Windows.Forms.Timer;请参阅 http://msdn.microsoft.com/en-us/library/system .windows.forms.timer.aspx [ ^ ]; 绝对避免使用此功能:即使使用起来比较简单,也很不准确.

—SA
Use a separate thread for this purpose and dynamically calculate sleep time between the lines asking the current time using System.DateTime.Now, calculate how much time to sleep and use System.Threading.Thread.Sleep.

Alternatively, use (sigh…) a timer. Timer seems easier to use, but in fact it''s harder to use it reliably. There are three timers in .NET:

System.Threading.Timer; see http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx[^];

System.Timers.Timer; see http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx[^];

System.Windows.Forms.Timer; see http://msdn.microsoft.com/en-us/library/system.windows.forms.timer.aspx[^]; avoid using this one by all means: it is very inaccurate even though it''s easier to use.

—SA


这篇关于如何在处理中包括时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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