Cancel a thread - please help

  • Thread starter Thread starter JJ
  • Start date Start date
J

JJ

Is there any way to allow the user to cancel a thread which carries out a
single long task. My form app's thread submits data to a web form via a
webclient instance. There is some considerable delay whilst the data is
retrieved. I am trying to avoid using thread.abort - is this possilbe?

My thread does a task similar to:

Dim wc As New Net.WebClient 'the webclient
Dim bt() As Byte 'the returned bytes
Dim html As String 'the returned HTML text
bt = wc.UploadValues(FormUrl, fields) 'send fields and retrieve response
<--** long task - would like to allow user to cancel it safely

Really need some help here,

Thanks
 
try this:

Dim myThread as New Thread(AddressOf myThreadBegin)

Private Sub myThreadBegin()

''Do work here

end sub

Private Sub Button1_Click(...)handles Button1.Click

try
myThread.Abort()

end sub
 
haha sry about that last post, let me finish the code here


Dim myThread as New Thread(AddressOf myThreadBegin)

Private Sub myThreadBegin()

''Do work here

end sub

Private Sub Button1_Click(...)handles Button1.Click

try

myThread.Abort()

catch ta as ThreadAbort

end sub
 
Thanks - finally a reply.
I think that its not possible to avoid a Thread.Abort in this scenario. So I
will use your approach here, unless someone can tell me otherwise.
 
Back
Top