event handler on closing console

mook

New member
Joined
Sep 26, 2006
Messages
1
Programming Experience
Beginner
Hi all,

I'm using .net framework 1.1 in building my console app, using VB.

In my main sub, I instantiate a number of threads to carry out work.

I want to create an event handler that will trigger when the console is closed, using x button, or ctrl_c - to check to see if my threads has completed their work, inorder to exit gracefully....need to be pointed in the right direction on how to handle this in 1.1

I checked on the web...but found most of console close event handling is new in .net 2.0

Thanks buckets!!:)
 
Just place code like...
VB.NET:
If not myThread is Nothing then
     If myThread.IsAlive then
          myThread.abort()
          myThread.join()
     End If
End If
at the end of your Sub Main inside of the console application; and this will insure it is the last thing that runs before the console application closes and will ensure your threads are killed.
However; if you want to let the threads finish their course then close use the code above and leave out the myThread.abort() function.




EDITED||||| I apologize. I see now that this isn't what you were looking for. You are looking for a way to catch the event of the user killing the application or it ending earlier in the code. I apologize but this will not work in that situation. My bad.
 
Back
Top