473,465 Members | 1,524 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

problem with teminate thread ... Thanks~~

Hi All,

my question is how to teminate a running thread...
it sounds simple but in fact i 'm having problem with it

firstly, i create a new thread (refer to follow example code) and start it
on form load
once the form button on clicked... i try terminate the thread... but an
exception was catched...

example code as follow..
Public Class CounterIncrement()
Public lngCounter As Long = 0

Pubilc Sub Increment()
Do
lngCounter += 1
Loop Until intCounter > 100000
End Sub
End Class

Public Class TestForm : Inherits System.Windows.Form

Private objThread As Thread()

Private Sub form1_load() handles form1.load
Dim objCounter As New CounterIncrement()

objThread = New Thread(AddressOf objCounter.Increment)
objThread.Start

Do
Application.DoEvents
Loop Until Not objThread.IsAlive
end sub

Private Sub button1_Click() handles button1.click
objThread.Abort <==== this won't terminate the thread... but make it
state as AbortRequested....?? why???
End Sub

End Class
Nov 20 '05 #1
4 1088
* "Ivan" <ic****@net-yan.com> scripsit:
my question is how to teminate a running thread...
it sounds simple but in fact i 'm having problem with it

firstly, i create a new thread (refer to follow example code) and start it
on form load
once the form button on clicked... i try terminate the thread... but an
exception was catched...

example code as follow..
Public Class CounterIncrement()
Public lngCounter As Long = 0

Pubilc Sub Increment()
Do
lngCounter += 1
Loop Until intCounter > 100000
End Sub
End Class

Public Class TestForm : Inherits System.Windows.Form

Private objThread As Thread()

Private Sub form1_load() handles form1.load
Dim objCounter As New CounterIncrement()

objThread = New Thread(AddressOf objCounter.Increment)
objThread.Start

Do
Application.DoEvents
Loop Until Not objThread.IsAlive
end sub

Private Sub button1_Click() handles button1.click
objThread.Abort <==== this won't terminate the thread... but make it
state as AbortRequested....?? why???
End Sub


Read the documentation about 'Thread.Abort'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
Usually the Abort method should be used as a last resort, a cleaner way,
such as a flag should be used.

--
HTH,
-- Tom Spink, Über Geek

Woe be the day VBC.EXE says, "OrElse what?"

Please respond to the newsgroup,
so all can benefit
"Ivan" <ic****@net-yan.com> wrote in message
news:ee*************@TK2MSFTNGP11.phx.gbl...
Hi All,

my question is how to teminate a running thread...
it sounds simple but in fact i 'm having problem with it

firstly, i create a new thread (refer to follow example code) and start it
on form load
once the form button on clicked... i try terminate the thread... but an
exception was catched...

example code as follow..
Public Class CounterIncrement()
Public lngCounter As Long = 0

Pubilc Sub Increment()
Do
lngCounter += 1
Loop Until intCounter > 100000
End Sub
End Class

Public Class TestForm : Inherits System.Windows.Form

Private objThread As Thread()

Private Sub form1_load() handles form1.load
Dim objCounter As New CounterIncrement()

objThread = New Thread(AddressOf objCounter.Increment)
objThread.Start

Do
Application.DoEvents
Loop Until Not objThread.IsAlive
end sub

Private Sub button1_Click() handles button1.click
objThread.Abort <==== this won't terminate the thread... but make it state as AbortRequested....?? why???
End Sub

End Class

Nov 20 '05 #3
Hi Ivan,

In addition to the answer from Herfried because in the documentation there
is as far as I know is not a "why", just that it is.

The thread is ended on its own after a while that there was no action
anymore.
However it is not real processing either.

So you should in my opinion not try to get the information if the thread is
running from the thread itself however from your program logic.

Just my thought,

Cor
Nov 20 '05 #4
thanks for your help...

"Cor Ligthert" <no**********@planet.nl> ¦b¶l¥ó
news:u3**************@TK2MSFTNGP12.phx.gbl ¤¤¼¶¼g...
Hi Ivan,

In addition to the answer from Herfried because in the documentation there
is as far as I know is not a "why", just that it is.

The thread is ended on its own after a while that there was no action
anymore.
However it is not real processing either.

So you should in my opinion not try to get the information if the thread is running from the thread itself however from your program logic.

Just my thought,

Cor

Nov 20 '05 #5

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

Similar topics

4
by: cedric | last post by:
hello, I encounter a problem using threads. I have a simple code to use a thread : cSurveillanceBorne = New clsThreadSurveillance _SurveillanceThread = New Thread(AddressOf...
2
by: Andrew Rawnsley | last post by:
Downloaded the eRServer 1.2 source (thanks, guys) and installed, and am having a problem. Anyone else dug into this yet? Situation: PG 7.3.4 on linux (master) Its been tried with 3 slaves,...
4
by: Madhu Gopinathan | last post by:
Hi All, I am faced with a horrible hang problem. I have a COM exe server that executes some tasks. The task execution manager is a thread that manages the pool of threads, which is 4 per processor....
8
by: Nadav | last post by:
Hi, Introduction: ********************* I am writing a mixed mode application I have a COM module and a .NET module that communicate with each other. The COM exposes a custom sink interface,...
5
by: Segfahlt | last post by:
I need a little help here please. I have 2 win forms user controls in 2 different projects that I'm hosting in 2 different virtual directories. The controls have been test and operate okay in...
10
by: Bryce Calhoun | last post by:
Hello, First of all, this is a .NET 1.1 component I'm creating. SUMMARY ----------------------- This component that I'm creating is, for all intents and purposes, a document parser (I'm...
0
by: Eric | last post by:
hi, I'am writing an instant messager that needs file transfer function. I have made it with command protocol-based( e.g. such as ftp : 220... ) it can works as begin sending initial command like...
2
by: sameer | last post by:
Hi guys, thanks in advance. trying to implement some multithreading here : VS 2003 VB.net winforms I have a dropdown on a form which has list of vendors, when the user selects a vendor...
18
by: J.K. Baltzersen | last post by:
To whomever it may concern: I am using MS Visual C++ 6.0. I have a process A which instantiates an object C. At a later point the process A creates the thread B. The thread B has access...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
1
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.