Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 26-Apr-12 7:21am
v2
Comments
Sergey Alexandrovich Kryukov 25-Apr-12 14:00pm    
Not clear what is it. Please use "Improve question" above and explain your idea in sufficient detail, perhaps with some examples. What is "to judge", to "determine"?
--SA

You can use the Stopwatch class here[^] to do what you want.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Apr-12 14:27pm    
I would say, this is the most accurate way of timing, a 5.
--SA
[no name] 25-Apr-12 14:30pm    
Thanks
VJ Reddy 25-Apr-12 20:30pm    
Good answer. +5
[no name] 25-Apr-12 20:42pm    
Thanks
Hello

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

VB
IF MyMethod.TakeLong <= 5ms THEN RUN MYMethod


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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900