PC Review


Reply
Thread Tools Rate Thread

How to abort a thread while close the form?

 
 
yxq
Guest
Posts: n/a
 
      10th Apr 2004
Hello
There is a thread in my form, when user click the Close button on form, i
want to abort the thread, then close the form, but my code seem not to work.

Private Sub frm_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

'I do not know whether the thread is running.

Dim blnThreadRunning As Boolean
Try
Dim a As String = MyThread.ThreadState()
blnThreadRunning = True
Catch
blnThreadRunning = False
End Try

If blnThreadRunning = True Then
Do Until MyThread.ThreadState = ThreadState.Aborted
Try
MyThread.Abort()
Catch
End Try
Loop
End If
End Sub


 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      10th Apr 2004
"yxq" <(E-Mail Removed)> schrieb
> Hello
> There is a thread in my form, when user click the Close button on
> form, i
> want to abort the thread, then close the form, but my code seem not
> to work.
>
> Private Sub frm_Closing(ByVal sender As Object, ByVal e As
> System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
>
> 'I do not know whether the thread is running.
>
> Dim blnThreadRunning As Boolean
> Try
> Dim a As String = MyThread.ThreadState()
> blnThreadRunning = True
> Catch
> blnThreadRunning = False
> End Try
>
> If blnThreadRunning = True Then
> Do Until MyThread.ThreadState = ThreadState.Aborted
> Try
> MyThread.Abort()
> Catch
> End Try
> Loop
> End If
> End Sub


Try
mythread.abort
mythread.join
instead.

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Thread: Thread.Abort() and SmtpMail does not work thougether? =?Utf-8?B?V2lsbHkgUw==?= Microsoft Dot NET Framework 4 13th Jan 2006 03:30 PM
Thread Abort --> close connection LP Microsoft C# .NET 6 19th Mar 2005 12:05 AM
how to force Thread.Abort() to Abort ? Andy Fish Microsoft C# .NET 13 22nd Jan 2005 05:09 PM
When I call form.show in a thread it close when the thread completes. PAPutzback Microsoft VB .NET 8 22nd Dec 2004 09:58 PM
Shut down thread - thread closes form, form doesn't close because thread calls it etc... Robin Tucker Microsoft VB .NET 4 17th Oct 2003 12:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:21 PM.