give WaitForResponse() a time limit? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
joshatt
Posts: 151
Joined: 07 Dec 2014, 08:41

give WaitForResponse() a time limit?

11 May 2020, 21:14

Hi all,
Here's a code from documentation:

Code: Select all

whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", "https://random.random2.com/", true)
whr.Send()
; Using 'true' above and the call below allows the script to remain responsive.
whr.WaitForResponse()
version := whr.ResponseText
MsgBox % version
If that site is down for now, after about 30 seconds, it will popup an error window "Error: 0x80072EE2 .... timeout.....WaitForResponse....."
I don't want that error window. How can I give it a 15 seconds limit, then just continue the following code, e.g. test another site?
Or even better: give it a 15 seconds limit, AND, if it turned out failed BEFORE 15 seconds, continue the following code without popup?
User avatar
boiler
Posts: 16963
Joined: 21 Dec 2014, 02:44

Re: give WaitForResponse() a time limit?  Topic is solved

11 May 2020, 21:31

How about just letting it reach the point where it gives the error but use Try/Catch to handle whether it errors out or not?
joshatt
Posts: 151
Joined: 07 Dec 2014, 08:41

Re: give WaitForResponse() a time limit?

12 May 2020, 00:14

How about just letting it reach the point where it gives the error but use Try/Catch to handle whether it errors out or not?
Terrific! Never learned this.
joshatt
Posts: 151
Joined: 07 Dec 2014, 08:41

Re: give WaitForResponse() a time limit?

12 May 2020, 00:58

boiler wrote:
11 May 2020, 21:31
How about just letting it reach the point where it gives the error but use Try/Catch to handle whether it errors out or not?
create,open,send,waitfor......which must be included in Try{}, in this case ?
User avatar
boiler
Posts: 16963
Joined: 21 Dec 2014, 02:44

Re: give WaitForResponse() a time limit?

12 May 2020, 01:06

It looks like you are getting the error from WaitForResponse, but the good thing is you don’t have to decide. You can put all of them inside the Try { }, and whatever causes an error will trigger the Catch.
joshatt
Posts: 151
Joined: 07 Dec 2014, 08:41

Re: give WaitForResponse() a time limit?

12 May 2020, 01:21

boiler wrote:
12 May 2020, 01:06
It looks like you are getting the error from WaitForResponse, but the good thing is you don’t have to decide. You can put all of them inside the Try { }, and whatever causes an error will trigger the Catch.
OK, thanks a lot, appreciate it.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: SimmoF, uchihito and 229 guests