CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1

    function timeout

    how to end a function before it returns? sort of timeout and exit.. how do u do it in VB?


  2. #2
    Join Date
    Sep 1999
    Posts
    17

    Re: function timeout

    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.




  3. #3
    Guest

    Re: function timeout

    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?


  4. #4
    Join Date
    Sep 1999
    Posts
    17

    Re: function timeout

    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!


  5. #5

    Re: function timeout

    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






Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured