Sometimes, my function will hang. If the function is longer than 3 seconds. I want to quit from this function, how to do this?
Thanks
Well, you should probably just figure out why it is hanging. If it is taking a long time to do the work then perhaps you could be doing something more efficiently. If it needs more than three seconds than how will breaking in the middle help you? The assumption is that the work actually needs to be done.
What call is hanging? If you don't own the code to the call that is hanging you're SOL unless you run it on another thread and create a timer to watch it.
This sounds to me like it may be a case of trying to find an answer to the wrong question, but perhaps you are waiting on a connection or some operation that should have a timeout period. With the information (or lack thereof) you have given us it is impossible to tell which is true. How about posting some code so that we are able to give a more definitive answer?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With