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 CounterIncremen t()
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 CounterIncremen t()
objThread = New Thread(AddressO f objCounter.Incr ement)
objThread.Start
Do
Application.DoE vents
Loop Until Not objThread.IsAli ve
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 4 1098
* "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 CounterIncremen t() 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 CounterIncremen t()
objThread = New Thread(AddressO f objCounter.Incr ement) objThread.Start
Do Application.DoE vents Loop Until Not objThread.IsAli ve 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/>
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******** *****@TK2MSFTNG P11.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 CounterIncremen t() 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 CounterIncremen t()
objThread = New Thread(AddressO f objCounter.Incr ement) objThread.Start
Do Application.DoE vents Loop Until Not objThread.IsAli ve 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
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
thanks for your help...
"Cor Ligthert" <no**********@p lanet.nl> ¦b¶l¥ó
news:u3******** ******@TK2MSFTN GP12.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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 cSurveillanceBorne.SurveilleBorne)
_SurveillanceThread.Start()
This code work perfectly on my workstation. I use Visual Studio 2003, and
the CLR version is 1.1.4322.573
|
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, all 7.3.4, 2 on OS X and one on Linux.
It builds fine. It installs fine. I go through the setup with no
problems (calling createlang, doing the initial ers_setup, adding
|
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. Each task is processed in a separate thread. Each of the executer threads is an STA thread, and it goes ahead and executes the task.
No problems are encountered when tasks are executed one at a time, but when multiple tasks are executed...
|
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, the .NET module implement the Sink
interface ( IUnknown based ) and the COM call the methods of this interface
asynchronously.
|
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 both projects.
Both controls(dlls) have been signed using SN.exe and I've set up the
appropriate .Net assembly permissions using those Strong Names
The DLL's have been copied to the /bin directory in both web virtual
directories.
| |
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 actually deserializing a SOAP document into an
object and parsing out the fields, but that's fairly immaterial to this
|
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 FILESIZE 200 and
FILESIZEOK 220...
however, while the data file transfer complete. the last command FILEEND 280
and FILEENDOK 290
not works as expected. the apps can't teminate the connection. how can I
make this works
server-side:
|
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 from this dropdown, a new thread is created which calls a webservice
and the webservice returns the list of cities the vendor is in and this data
|
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 to the object C.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |