473,386 Members | 1,708 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,386 software developers and data experts.

how to end a thread without an exception?

buu
I have a thread that ends with system.threading.thread.currentThread.Abort()
method..
..
but, it throws me an exception..
is there any other way to end a thread?
Mar 11 '08 #1
3 1999
buu wrote:
I have a thread that ends with system.threading.thread.currentThread.Abort()
method..
.
Don't do that. Ever.
but, it throws me an exception..
is there any other way to end a thread?
Sure! Just return from your thread routine and the thread will be over.

To end a thread from another thread, set a boolean, then have the thread
that needs to end check for that boolean and return from its thread routine.

The only safe (and dare I say useful) way to end a thread is by explicitly
synchronizing. There is no safe way to simply "end" a thread without knowing
what it's doing, so it's better to let the thread end itself by signaling it.

--
J.
Mar 11 '08 #2
Hello buu,
I have a thread that ends with
system.threading.thread.currentThread.Abort()
method..
.
but, it throws me an exception..
is there any other way to end a thread?
Well when you start a thread you give it a procedure to run.
So you could trip some internal flag (viewable by the proc) which will allow
the procedure to come to a natural end.

--
Rory
Mar 11 '08 #3
a a


*** Sent via Developersdex http://www.developersdex.com ***
Mar 31 '08 #4

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

Similar topics

1
by: Christopher D. Wiederspan | last post by:
I've got a WebServices application that uses Crystal Reports to produce and then export Invoices to PDF format. Without getting into too many details, it's just a big loop statement that goes out...
4
by: Daylor | last post by:
in win32 process , when u create new process,u have new main thread. i know,appDomain r logical procces,that exists in 1 win32 process. the q: is there way to create second appDomain (the...
11
by: Bob Rock | last post by:
Hello, coming from win32 API I recall an ExitThread() call to gently terminate a thread from inside the same thread .... but now all I can see is an Abort call which seems to me a wrapper on the...
31
by: AlexeiOst | last post by:
Everywhere in documentation there are recommendations to use threads from thread pooling for relatively short tasks. As I understand, fetching a page or multiple pages (sometimes up to 50 but not...
3
by: Niyazi | last post by:
Hi, I created application that I get information from AS400 for reporting. In main.exe has only 1 frm which calls (as a class library) CLS_MAIN.dll. The CLS_MAIN.dll get the tables from AS400...
7
by: David Elliott | last post by:
I have created an application that will dynamically load other DLLs (plugins). The new plugin is a winform with an embedded IE Browser. I am wanting to have the form to run in its own thread....
18
by: Urs Vogel | last post by:
Hi I wrote an application server (a remoting sinlgeton), where processes must be stopped in very rare cases, done thru a Thread.Abort(). Occasionally, and only after a Thread.Abort(), this...
4
by: Bob Day | last post by:
Using VS 2003, VB, MSDE... I am stoping a thread with the following code: Try Thread.CurrentThread.Abort() Catch ex As Exception MessageBox.Show(ex.ToString)
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...
20
by: =?ISO-8859-1?Q?Gerhard_H=E4ring?= | last post by:
John Dohn wrote: When I do this, I put a special value in the queue (like None) and in the worker thread, check for the special value and exit if found. Threads can also be marked as "daemon...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.