Cancel a thread - please help

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
 
G

Guest

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
 
G

Guest

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
 
J

JJ

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top