Home All Groups Group Topic Archive Search About

Cancel a thread - please help

Author
30 Jan 2006 1:40 PM
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

Author
30 Jan 2006 8:58 PM
iwdu15
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

--
-iwdu15
Author
30 Jan 2006 9:00 PM
iwdu15
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


--
-iwdu15
Author
31 Jan 2006 8:34 AM
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.




Show quoteHide quote
"iwdu15" <jmmgoalsteratyahoodotcom> wrote in message
news:B70A85C8-30A1-4515-84B2-D5D32B7E9F37@microsoft.com...
> 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
>
>
> --
> -iwdu15
>