如何在X时间执行代码执行 [英] How Can I Do Code Execution For X Time

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

问题描述

你好我的程序中有很多代码我在x时间做了什么代码

例如:



代码
..
时间( 10000 ' 10秒
...
' 一些代码
...
结束时间

其余代码。





最好的办法是什么。



感谢

解决方案

可能你是以错误的方式解决这个问题:而不是试图限制代码段可以运行的时间(这不会很简单,具体取决于您正在做什么,以及您是如何做的),您可能希望考虑将长时间运行的代码移动到一个单独的线程中d让它连续运行。



我会从你的伪代码中假设你是从某个来源录制日期,并且只想显示少量它。如果是这样,他们将数据接收过程移动到另一个线程可能是一个更好的解决方案。



看看BackgroundWorker类是否有一个简单的方法来做到这一点

Hello i have a lot of code in one place in my program i what to do the code for x time
for example:

code
..
 time(10000) ' 10 sec
  ...
   'some code
  ...
 End time

'rest of the code.



Whats the best way to do it.

Thank's

解决方案

Probably, you are going about this the wrong way: instead of trying to limit the amount of time that your code segment can run (which is not going to be simple, depending on exactly what you are doing, and how you are doing it) you might want to consider moving the long running code into a separate thread and letting it run continuously.

I would assume from your pseudocode that you are recording date from some source, and only want to display a small amount of it. If so, them moving the data receive process into a different thread would probably be a better solution.

Have a look at the BackgroundWorker class for a simple way to do this.


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

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