在特定时间后执行语句 [英] Execute Statement After Specific Time

查看:76
本文介绍了在特定时间后执行语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是问题所在,我正在使用的程序正在通过串行端口获取十个样本并将其写入文件.
但是,现在我想进行三个采样,因此首先采样然后等待特定的时间,然后执行下一个采样,依此类推.我已经读过Threading.Sleep()会影响事件,我的串行端口是事件驱动的,是否存在另一个可以递减计数或递增计数的方法?

So here is the problem, the program that I am currentyl working on takes samples of ten via the serial port and writes them to a file.
Now however, I want to take three samples, so take first sample then wait a specific time, then execute the next sampl and so on. I have read that Threading.Sleep() effects events, My serial port is event driven is there a another method that exists that can either count down or up to a time??

推荐答案

好吧,您可以看一下计时器类 [ ^ ] ...
Well, you could look at the Timer class[^]...


如果您在单独的线程中进行工作, a> [^ ]或 BackgroundWorker [
If you do your work in a separate Thread[^] or a BackgroundWorker[^] you can use Thread.Sleep() without problems.

Cheers!


这篇关于在特定时间后执行语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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