VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,837 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello experts,
Here's a custom WebClient class allowing to set a custom timeout, I think it's not honoring the timeout correctly, but can't find where's the problem with the class, anyone can help please? :)
Am I doing the initialize and dispose correctly?
Peace.
Friend Class _WebClient
Inherits Net.WebClient
Private _TimeoutMS As Integer = 0
Friend Sub New()
MyBase.New()
End Sub
Friend Sub New(ByVal TimeoutMS As Integer)
MyBase.New()
_TimeoutMS = TimeoutMS
CachePolicy = New Cache.HttpRequestCachePolicy(Cache.HttpRequestCacheLevel.NoCacheNoStore)
CachePolicy = New Cache.RequestCachePolicy(Cache.RequestCacheLevel.NoCacheNoStore)
Encoding = Encoding.ASCII
Headers.Add("user-agent", "Mozilla/5.0 (Compatible; MSIE 11.0; Windows NT 10.0; .NET CLR 4.0.30319)")
End Sub
Protected Overrides Sub Dispose(ByVal Disposing As Boolean)
MyBase.Dispose(Disposing)
End Sub
Private WriteOnly Property SetTimeout() As Integer
Set(ByVal Value As Integer)
_TimeoutMS = Value
End Set
End Property
Protected Overrides Function GetWebRequest(ByVal Address As System.Uri) As Net.WebRequest
Dim MyWR As Net.WebRequest = MyBase.GetWebRequest(Address)
If _TimeoutMS = 0 Then
MyWR.Timeout = 5000
Else
MyWR.Timeout = _TimeoutMS
End If
Return MyWR
End Function
End Class