473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to abort a thread while close the form?

yxq
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
Nov 20 '05 #1
2 3445
"yxq" <ga***@163.net> 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

Nov 20 '05 #2
"yxq" <ga***@163.net> 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

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Stephan Steiner | last post by:
Hi I'm having some weird threading issues.. almost at random, if I dare change a line of my code, the shutdown sequence gets messed up. I'm using a thread to receive data from the network, that...
20
by: Doug Thews | last post by:
I ran into an interesting re-pain delay after calling the Abort() method on a thread, but it only happens the very first time I call it. Every time afterward, there is no delay. I've got a...
2
by: MuZZy | last post by:
HI, As i posted below i have an app with a separate thread listening for a tcp client connection. In the simplest way it looks like: void ListenerThreadFunction() { TcpListener l = new...
2
by: yxq | last post by:
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...
6
by: Sakharam Phapale | last post by:
Private myThread As Thread Sub cmdStart_Click() myThread = New Thread(AddressOf PlayAudio) myThread.Start End Sub Sub PlayAudio() Open wave file Play wave file
6
by: Joe HM | last post by:
Hello - I have a function that calls Thread.Abort() to stop a thread in a _Closed() Method of a GUI. The thread contains a blocking call on a TCP socket and that is the easiest way to stop...
5
by: andrew | last post by:
Hi, I have the following issue with the Thread.Abort(): The main thread creates a worker thread which waits on a process termination. void ThreadProc() { Process proc =...
7
by: Marc Bartsch | last post by:
Hi, I have a background worker in my C# app that makes a synchronous HttpWebRequest.GetResponse() call. The idea is to POST a file to a server on the internet. When I call HttpWebRequest.Abort()...
7
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, In my Windows application, I'm using thread, and I've 2 questions: 1. I read that it's not recommended to use Thread.Abort(), so what is the best way to close the thread, in case the user...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.