C#如何确定函数的运行状态 [英] C # How to determine a function's running Operation

查看:88
本文介绍了C#如何确定函数的运行状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想判断C#中某个函数的运行操作.我想获得一个函数的运行时间,如果该函数的运行时间超过1秒(或其他时间),然后继续运行后面的代码,请跳过该函数.如何实现我想要的这种功能?谢谢.

I would like to judge the running operation of a function in C#. I want to get a function''s running time,if the running time of this function over 1 seconds (or other time)then continue to run the behind code,skip this function. How do I achieve what I want such a feature? Thank you.

推荐答案

您可以使用Stopwatch类
You can use the Stopwatch class here[^] to do what you want.


你好

如果我理解您的意图,则希望程序在调用方法之前猜测一下执行该方法的时间.例如:

Hello

If I understand your intention, you want the program guess the during time of executing a method before calling it. For example:

IF MyMethod.TakeLong <= 5ms THEN RUN MYMethod



如果您想要它,我建议您忘记它.这是非常非常复杂且有很高的错误风险.

我认为您可以在另一个线程中调用一个方法,并在花费n秒后中止该线程.



If you want it I suggest that forget it. It''s very very complicated and high mistake risk.

I think you can call a method in another thread and after taking n seconds then abort the thread.


这篇关于C#如何确定函数的运行状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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