473,394 Members | 1,845 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.

Killing a thread

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)

End Try

The MessagBox shows, but then after the End Try it traverses the call stack
all the way to the top (same thread) and the exception is caught again by a
Try/Catch that is around everthing that happens in this thread.

1) Why does the top level try catch get involved at all when it is caught
locally?

2) I don't really want to thow an exception, I just want to kill the thread.
It seems that setting it to nothing accomplishes the same thing. Is there
any disadvantage to doing it this way?

Thanks!
Bobg
Nov 20 '05 #1
4 1182
Bob,
1) Why does the top level try catch get involved at all when it is caught
locally?
Thread.Abort() throws a ThreadAbortException. According to its
documentation

"ThreadAbortException is a special exception that can be caught, but
it will automatically be raised again at the end of the catch block."

You can't both terminate a thread and still execute code on it.

It seems that setting it to nothing accomplishes the same thing.


How did you come to that conclusion? Setting a reference to Nothing
doesn't terminate a thread.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 20 '05 #2
Well, then, is ther any way to kill a thread other that .Abort? Without
throwing an exception?

Thanks
Bob Day

"Bob Day" <Bo****@TouchTalk.net> wrote in message
news:OL****************@tk2msftngp13.phx.gbl...
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)

End Try

The MessagBox shows, but then after the End Try it traverses the call stack all the way to the top (same thread) and the exception is caught again by a Try/Catch that is around everthing that happens in this thread.

1) Why does the top level try catch get involved at all when it is caught
locally?

2) I don't really want to thow an exception, I just want to kill the thread. It seems that setting it to nothing accomplishes the same thing. Is there
any disadvantage to doing it this way?

Thanks!
Bobg

Nov 20 '05 #3
Yes, set a flag in the thread - if your thread executes a loop that is, then
"while not bDone" - other thread sets "bDone" to true when it wants the
thread to stop. Of course, you will have no way of knowing exactly when the
thread has stopped (it might execute another iteration).
"Bob Day" <Bo****@TouchTalk.net> wrote in message
news:um****************@TK2MSFTNGP12.phx.gbl...
Well, then, is ther any way to kill a thread other that .Abort? Without
throwing an exception?

Thanks
Bob Day

"Bob Day" <Bo****@TouchTalk.net> wrote in message
news:OL****************@tk2msftngp13.phx.gbl...
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)

End Try

The MessagBox shows, but then after the End Try it traverses the call stack
all the way to the top (same thread) and the exception is caught again by a
Try/Catch that is around everthing that happens in this thread.

1) Why does the top level try catch get involved at all when it is

caught locally?

2) I don't really want to thow an exception, I just want to kill the

thread.
It seems that setting it to nothing accomplishes the same thing. Is there any disadvantage to doing it this way?

Thanks!
Bobg


Nov 20 '05 #4
Hi Bob,

I agree with Robin's suggestion, if you still have any question on this
issue, please feel free to post here, and I will work on your with it.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #5

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

Similar topics

6
by: Colin Steadman | last post by:
I have created a function to kill all session variables that aren't in a safe list. This is the function - Sub PurgeSessionVariables For Each Item In Session.Contents Select Case Trim(Item)...
1
by: Amendra | last post by:
hi, I have a Parent child design of a multi threaded application in C#. My issue is I want the parent class to be able abort or stop the child threads. I tried abort from the parent, then the...
10
by: Jacek Pop³awski | last post by:
Hello. I am going to write python script which will read python command from socket, run it and return some values back to socket. My problem is, that I need some timeout. I need to say for...
1
by: Hasani | last post by:
When I'm done using a thread, do I do Abort or do nothing and the run time will kill it for me? also, can I call Join a thread after I call Abort on that same thread?
5
by: Saurabh Sharma | last post by:
Hi I have made a Windows Form and in it few calculations and processos are running. When i close the form the process continues to run until that particular function in finished. I cant use...
2
by: Sgt. Sausage | last post by:
New to multi-threading (less than 24 hours at it <grin>) Anyway, it's all making sense, and working fairly well thus far, but I'm having a minor issue I'm not sure how to get around. I've got...
8
by: Rob | last post by:
Hello, I've got an issue where a process in a third party application has a dll which while exiting sort of freezes and runs away with processor cycles. i've written a block of code so that I...
0
by: Maqbool | last post by:
Hi, I am intantiating thread that do more extensive work, i.e. executing query on FoxPro 2.6 through ODBCDataAdapter with VisualFoxPro driver. Since the query executing is Complex and navigating...
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...
6
by: Roger Heathcote | last post by:
sjdevnull@yahoo.com wrote: <snip> Fair point, but for sub processes that need to be in close contact with the original app, or very small functions that you'd like 100s or 1000s of it seems...
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: 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
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
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.