Time out in webclient possible ?

Antoine

Regular
Joined
Aug 12, 2003
Messages
58
Location
The Netherlands
Dear all,

I have written a piece of code to get information out of a number of IP camera's and import it using a webclient. But when the camera fails for some reason, the whole software stops responding, because it is waiting for the data that never comes.

Is there a possible way to let the webclient generate a time-out when there is no data for a certain amount of time ?

Visual Basic:
        Dim myWebClient As New System.Net.WebClient
        Try
            tmrVideoRefresh.Enabled = False
            Dim remoteUrl As String = CameraArray(CurrentCam, 2)
            Dim myDatabuffer As Byte() = myWebClient.DownloadData(remoteUrl)
            Dim MyMemoryStream As New System.IO.MemoryStream(myDatabuffer)
            Dim img As Image = Image.FromStream(MyMemoryStream)

            VideoBox(Val(CameraArray(CurrentCam, 1))).Image = img

            tmrVideoRefresh.Enabled = True
        Catch ex As System.Net.WebException
            MessageBox.Show(ex.Message)
            Exit Try
        Catch ex As Security.SecurityException
            MessageBox.Show(ex.Message)
            Exit Try
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Exit Try
        End Try

Thanks in advance
Antoine

[edit]
Btw, I don't mind that it is taking 80 seconds to find out that it doesn't exist, but more the fact the the whole application stands still (I thought windows was multitasking ?), is there a way to make it run in the background or something ?
[/edit]
 
Last edited:
I don't know anything about webclients...are there any async functions to download the data? If not, create a thread for the download data function and start a timer when you call that thread. If the timer elapses and the thread is still running, stop it. Oh and make sure to stop and restart the timer each time the thread ends.
 
Back
Top