stop connection

leontager

Regular
Joined
Jun 17, 2003
Messages
89
I am using a stream to connect to a website and retrieve the source. I would like to be able to automaticly stop hte process if the website does not work. so I implemented a timer and set the interval to 10 seconds. now I would like to stop the stream from attemting to connect the the website. would this be possible?

Timer2.Enabled = True
Timer1.Interval = 10000
stream = New IO.StreamReader(wc.OpenRead(ChooseURL(m)))
Timer2.Enabled = False


Private Sub Timer2_Tick(ByVal Sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
Timer2.Enabled = False
End Sub

Now keep in mind that this is the second time I ever used a timer so I am not too familiar with how it works. If I am doing something wrong please correct me. Thank you.
 
Why do you do those first 4 lines of code??
2 timers?? Why??

The Timer object have 3 Main methods... Interval, Start & Stop

Interval - Set the interval of time that must ellapse betwin timer ticks.
Start & Stop - Starts and stops the timer from Ticking.

So use it like this:

Visual Basic:
Timer1.Enabled = True
Timer1.Interval = 10000
Timer1.Start

Private Sub Timer1_Tick(ByVal Sender As Object, ByVal e As EventArgs) Handles Timer1.Tick

stream = New IO.StreamReader(wc.OpenRead(ChooseURL(m)))

End Sub


If you want to stop the Stream to try to read from the URL just stop the Timer Ticking calling:

Visual Basic:
Timer1.Close


Worked?
 
Back
Top