Click to See Complete Forum and Search --> : function timeout


Muthu Ram
September 21st, 1999, 03:46 PM
how to end a function before it returns? sort of timeout and exit.. how do u do it in VB?

shanep
September 22nd, 1999, 12:38 AM
There is article in the VB docs titled "Interrupting Background Processing".

Maybe timer controls are what you need so the following may help you out.

Use a timer control along with a global variable to keep track of how much time has passed in your function. Test the variable in your function to see if hits that point.

1. Create a timer with some interval (1000 is good). Set the enabled property to false.
(Note: keep in mind if your function is making heavy use of system resources, you may not get timer events on time. Tinker around with the interval value)

2. In the timer event for tmrTimer, increment that global value.

3. At the beginning of your function call, enable the timer control. Now the rest depends on your function. If your function requires several sequential steps, then you will have to test the global several times. If there's a loop that requires a lot of background processing then, you can just add that condition. Hopefully, your system won't be so bogged down in processing that it will not handle the timer events reliably.

September 22nd, 1999, 05:05 PM
the problem is i am calling an windows api function. for some of the requests it returns quickly and it takes time for other. i should be able to kill the function or end it somehow after a while.. any ideas?

shanep
September 23rd, 1999, 11:56 PM
Most api calls return a handle of some kind.

I read your post on HttpSendRequestEx. Is this related? For that problem, store that HINTERNET handle at your module or form level. Then, in your timer event I posted earlier, I believe you can close it with this API call.

BOOL InternetCloseHandle(
IN HINTERNET hInternet
);

Hope this helps!

Muthu Ram
September 24th, 1999, 11:38 AM
i figured out you have to use InternetSetStatusCallback function and register a callback function to check the status. now in this callback, i can end the request based on the status. ending the request will be done as you said using InternetCloseHandle.


' set the callback function
public Declare Function InternetSetStatusCallback Lib "wininet.dll" _
Alias "InternetSetStatusCallbackA" (byval hInternet as Long, _
byval lpfnInternetCallback as Long) as Long