I am wanting to create a HTTP web request with a time out so that my program isn't delayed several minutes trying to connect to a website if it isn't online.
What I am currently doing is downloading strings from a plain txt file which is on my local host and I am doing this with webclient.downloadstring.
But the webclient doesn't have a timeout function so the only other thing is to make a timer but the thing is because I am downloading the string during the form load process the timer doesn't function after the form is loaded, so that doesn't work for me.
So I was thinking is it possible to use a http web request with a time out on the form load event and then when it times out, I could continue with something else.
This is the basic http web request:
But then how would I create an if condition knowing it's timed out? "If myWebRequest.Timeout = 2000"?
What I am currently doing is downloading strings from a plain txt file which is on my local host and I am doing this with webclient.downloadstring.
But the webclient doesn't have a timeout function so the only other thing is to make a timer but the thing is because I am downloading the string during the form load process the timer doesn't function after the form is loaded, so that doesn't work for me.
So I was thinking is it possible to use a http web request with a time out on the form load event and then when it times out, I could continue with something else.
This is the basic http web request:
vb.net Code:
Dim myWebRequest As Net.HttpWebRequest Dim myWebResponse As Net.HttpWebResponse myWebRequest = Net.WebRequest.Create("http://127.0.0.1") myWebRequest.Timeout = 2000 myWebRequest.KeepAlive = True myWebRequest.Credentials = Net.CredentialCache.DefaultCredentials myWebResponse = myWebRequest.GetResponse() myWebResponse.Close()
But then how would I create an if condition knowing it's timed out? "If myWebRequest.Timeout = 2000"?