在C#中设置可设置的时间延迟 [英] Making a settable time delay in C#
问题描述
是否可以在C#代码中进行延迟,以便如果我想在代码中的某些点上实现3秒钟的延迟,那么只需将代码保留3秒钟,然后再继续操作即可?我正在尝试制作一个要进行测量的程序,我需要它来运行实验室仪器一段时间,而不是在运行时在代码中进行任何处理.我还希望能够从用户界面更改时间延迟,而不必更改代码.
谢谢,
SVandal
Is it possible to make a delay in the C# code such that if I wanted to make it possible to have a 3 second delay at certain points in the code that would simply hold the code for 3 seconds and then continue on again? I am trying to make a program that will take measurements and I need it to run the lab instrument for a set time, and not progress in the code while it is running. I would also like to be able to change the time delay from the user interface rather than having to change the code.
Thanks,
SVandal
推荐答案
您可以使用以下代码暂停当前应用线程:
You can pause current app thread by using this code:
System.Threading.Thread.Sleep(3000);
System.Threading.Thread.Sleep(3000);
这篇关于在C#中设置可设置的时间延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!