calling a function and then killing the process if it takes more time

kaisersoze

Centurion
Joined
Aug 27, 2003
Messages
152
I need to calling a function. If the funtion takes more time to execute then I need to come out of the function. Is there a way. currently my application works as it should, but when bad network, the same function takes time to return, so, the app should try for 30 secionds, if time taken to execute is more than 30 seconds then move forward with next step.

please help
 
This is exactly what threading is for. You need to launch this function in a separate thread. This means that the main thread is still free to update the ui and interact with the user (in other words, the program isn't frozen). Since I hardly even qualify as a multithreading novice, that's about all I can tell you, but I'm pretty sure you can find all the help you need on threading in MSDN.
 
If you're using .net 2.0, check out the BackgroundWorker class, otherwise use advice mentioned above.
If you're using wincontrols, you can use the Control.BeginInvoke method.
 
Back
Top