473,387 Members | 1,876 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,387 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
Jul 21 '05 #1
2 1266
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

Jul 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/>
Jul 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: 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: 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. ...
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
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...

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.