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

Quit program cleanly

Hi,
I have a program, that makes use of threads. Now when I quit the
program from the upper right button of the window, the threads are not
terminated and the program is still is running.

How can I handle the event for that button.

Thanks in Advance
Nov 16 '05 #1
4 2802


Simple. Code what your thread stopping handler into the "closing"
event of the form.

got a code problem? hand it to the devil.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #2
Call Thread.Abort, then Thread.Join.
This causes a ThreadAbortException to be raised in the thread, and this is
an exception that 'rethrows' itself. Although I'm not sure of the exact
semantics of this, what I do know IIRC though is that
a) you need to handle any thread cleanup code in the 'finally' of the
exception handler that can catch a threadabortexception.
b) when the calling thread has called 'Join', and that call returns, it can
be confident the thread is dead.

"Xarky" wrote:
Hi,
I have a program, that makes use of threads. Now when I quit the
program from the upper right button of the window, the threads are not
terminated and the program is still is running.

How can I handle the event for that button.

Thanks in Advance

Nov 16 '05 #3
Do *not* call Thread.Abort. See

http://www.interact-sw.co.uk/iangblo...2/cancellation

and my reply

http://www.dotnetconsult.co.uk/weblo...1-6ca6992460ca

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Call Thread.Abort, then Thread.Join.
This causes a ThreadAbortException to be raised in the thread, and this is
an exception that 'rethrows' itself. Although I'm not sure of the exact
semantics of this, what I do know IIRC though is that
a) you need to handle any thread cleanup code in the 'finally' of the
exception handler that can catch a threadabortexception.
b) when the calling thread has called 'Join', and that call returns, it can
be confident the thread is dead.
Nov 16 '05 #4
Hi,

You have to declare the thread as background

From MSDN:
A managed thread is either a background thread or a foreground thread.
Background threads are identical to foreground threads with one exception: a
background thread will not keep the managed execution environment alive.
Once all foreground threads have been stopped in a managed process (where
the .exe file is a managed assembly), the system stops all background
threads and shuts down. A thread can be designated as a background or a
foreground thread by setting the Thread.IsBackground property. For example,
a thread can be designated a background thread by setting
Thread.IsBackground to true. A thread can likewise be designated a
foreground thread by setting IsBackground to false. All threads that enter
the managed execution environment from unmanaged code are marked as
background threads. All threads generated by creating and starting a new
Thread object are foreground threads. If you create a foreground thread that
you want to listen for some activity, such as a socket connection, you
should set Thread.IsBackground to true, so that your process can terminate.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Xarky" <be*********@yahoo.com> wrote in message
news:bc*************************@posting.google.co m...
Hi,
I have a program, that makes use of threads. Now when I quit the
program from the upper right button of the window, the threads are not
terminated and the program is still is running.

How can I handle the event for that button.

Thanks in Advance

Nov 16 '05 #5

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

Similar topics

5
by: BJ | last post by:
The application I have been developing is great except one flaw. When Windows NT shuts down, it doesn't send the Event to my application (if it did, it would close all of the open forms and kill an...
1
by: David Conorozzo | last post by:
I create a new Access.Application instance. As soon as I refernce the property "References", I am unable to issue a truly successful quit on that instance. By that I mean the call to quit is fine...
4
by: KB | last post by:
Hi, I want to write a Python script that controls and automates a Windows GUI computation program. My problem is that I do not know how to quit the Windows GUI program gracefully with a...
6
by: Max | last post by:
I have the following code on a form that launches Microsoft Outlook and creates a new email message for the user: Outlook.Application oApp = new Outlook.Application(); Outlook.MailItem oMail...
5
by: mzdude | last post by:
I've just started playing with Python. Installed 2.5 on Windows XP system. I'm working through some of the examples in Programming Python 3ed by Mark Lutz. Given the following example when the Quit...
5
by: cameron | last post by:
I am working on an assignment where I have to allow end-users to enter in data and to have C++ make a calculation. From there I have to set up a loop to allow users to go back and enter new data or...
4
by: Bob | last post by:
Hi, If the test is true, the message 'not available' must be shown and quit the program. But when the test is true and when table 'data2' is empty (so nrg=0), i get the error:"dividing by...
1
by: raul15791 | last post by:
Hi, I'm new to C#. I'm writing a program that open a new excel file, write into it and lastly close the file. But the program is that there will be a orphaned process named EXCEL.EXE left on the...
9
by: Andy | last post by:
Just noticed something interesting in the above. If you have your program file set to "Compact on Close" in access 2007 (which is desirable when you have a larger program that frequently needs...
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: 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?
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
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.