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

Terminating a thread from the main thread

Hello,

I have created a thread that writes data from a memorystream to the
harddrive. If the user, during the write decides to cancel the operation, I
call Abort on the thread.

i.e.

Private Sub WriteToDiskButton_Click
MyThread= New Threading.Thread(AddressOf WriteToDisk)
MyThread.Start()
End Sub

Private Sub WriteToDisk
Try
'do stuff
Catch Ex as System.Threading.ThreadAbortException
End Try
End Sub

Private Sub AbortButton_Click
MyThread.Abort
End Sub

When the Abort takes place I get two Abort Exceptions, I am able to catch
the fist one but how do I catch both exceptions so the user is not aware of
them.

Chuck
Nov 21 '05 #1
2 1004
Charles,

I think it is better to fine out why the exception is throwed, that should
not happen with just an abortion of a thread.

A try and catch is for situations when you cannot find that.

By instance when you know that a file exist on a shared disk, however don't
know if it is in use already.

Just my thought,

Cor

"Charles A. Lackman" <Ch*****@CreateItSoftware.net>
....
Hello,

I have created a thread that writes data from a memorystream to the
harddrive. If the user, during the write decides to cancel the operation,
I call Abort on the thread.

i.e.

Private Sub WriteToDiskButton_Click
MyThread= New Threading.Thread(AddressOf WriteToDisk)
MyThread.Start()
End Sub

Private Sub WriteToDisk
Try
'do stuff
Catch Ex as System.Threading.ThreadAbortException
End Try
End Sub

Private Sub AbortButton_Click
MyThread.Abort
End Sub

When the Abort takes place I get two Abort Exceptions, I am able to catch
the fist one but how do I catch both exceptions so the user is not aware
of them.

Chuck

Nov 21 '05 #2
Charles A. Lackman schrieb:
Private Sub AbortButton_Click
MyThread.Abort
End Sub

When the Abort takes place I get two Abort Exceptions, I am able to catch
the fist one but how do I catch both exceptions so the user is not aware of
them.


Add a handler to 'System.Windows.Forms.Application.ThreadException' in
order to catch the exceptions.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #3

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

Similar topics

3
by: DE | last post by:
Hello, I have an app with embedded Python. Python scripts create their own threads and I need to terminate these threads at the point where the user wants to leave the application. I use...
2
by: Charles A. Lackman | last post by:
Hello, I have created a thread that writes data from a memorystream to the harddrive. If the user, during the write decides to cancel the operation, I call Abort on the thread. i.e. ...
2
by: Byron | last post by:
I'm new to C# and threading, so hopefully this is a simple newbie question. I have a form that is supposed to listen for network traffic on a given port and decode and display any interesting...
0
by: Ginno | last post by:
Hello all Within my reports form i have used delegates to allow a crystall reports to generate without holding up the user. The user selects a report from tree view, enters the appropriate...
2
by: T Conti | last post by:
Hello: I created a basic windows service that polls a db and sends emails to our subscribers. In the onstart method I create a new thread and send it on its way to do work. It should never end...
2
by: Dave | last post by:
I have an application that queries SQL Server and Index Server using ADO. I'd like to have a feature where a user can cancel a long-running query. What I plan on doing is to move my query code to a...
23
by: Adam Clauss | last post by:
I have a C# Windows Service running as the NetworkService account because it needs to access a network share. As part of the service's initialization, I want the service to terminate, if an...
6
by: Tomaz Koritnik | last post by:
I have a class that runs one of it's method in another thread. I use Thread object to do this and inside ThreadMethod I have an infinite loop: While (true) { // do something Thread.Sleep(100);...
2
by: Adam Honek | last post by:
Hi all, I'm launching a form in a new thread as follows below. The problem is the form exits straight away. How do I cause it to stay open until the form is closed? The suspend won't work...
3
by: Martin Arvidsson | last post by:
Hi! I am starting up a thread that is listening for tcp connections in the thread i am using while (true) { // Handle the tcp stuff!! }
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...
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
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...
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
agi2029
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,...

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.