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

Cleaning up after the process is ended in task manager

I have a problem that relates to running "cleanup" code when an application
is forcibly ended using the "End Process" of "Task Manager" (Please note that
this is very different from "End Task" since end task sends a message to the
application, requesting it to close)

My real problem is that our application makes entries into a database when
the application starts, and then corresponding entries when the application
closes ("cleanup"). This application is run in a terminal session, and
disconnected sessions are forced closed after a certain amount of time has
passed, effectively ending all the processes of the terminal session. This is
equivalent to "End Process" of the application using Task Manager.

I'm unable to run any code when this happens, the code does not return after
the Application.Run(...) statement, so putting a try-catch-finally around it
doesn't work because it isn't run.

Adding event handlers to AppDomain.ProcessExit doesn't work, nor does adding
a MessageFilter to the Application's message loop.

How do I get code to run under these circumstances ?
Jul 21 '05 #1
4 1964
Hi Jaans,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to write clean up code even
the process is ended by TerminateProcess. If there is any misunderstanding,
please feel free to let me know.

As far as I know, this cannot be achieved. TerminateProcess is the
low-level process killing function. It bypasses DLL_PROCESS_DETACH and
anything else in the process. Once you kill with TerminateProcess, no more
user-mode code will run in that process. It's gone. For more information,
please check the following link:

http://weblogs.asp.net/oldnewthing/a...22/191123.aspx

In this case, I think you can do the clean up when process starts. You can
set a flag to see if the process is exit properly. If not, check it at the
beginning of your app, and do clean up.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #2
Hi Kevin

Yes your understanding is correct. Thank you for confirming what I suspected
might not be possible. The link also was helpfull.

This made me think about Terminal Server in particular. Is it issuing a
"TerminateProcess" to the processes running in a sessions when it has reached
it's disconnected timeout, or is it sending closing the applications some
other way?

We have done some tests (remote debugging), is it's behaviour is similar to
that experienced by "TerminateProcess".

Why I'm so interested in cleaning up, is that a GUID ticket is issed as a
form of "license control" when the application starts, which needs to be
"returned" when the application closes. I guess I'm going to have to change
it to issue tickets that "expire" or somthing like that.

Regards

"Kevin Yu [MSFT]" wrote:
Hi Jaans,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to write clean up code even
the process is ended by TerminateProcess. If there is any misunderstanding,
please feel free to let me know.

As far as I know, this cannot be achieved. TerminateProcess is the
low-level process killing function. It bypasses DLL_PROCESS_DETACH and
anything else in the process. Once you kill with TerminateProcess, no more
user-mode code will run in that process. It's gone. For more information,
please check the following link:

http://weblogs.asp.net/oldnewthing/a...22/191123.aspx

In this case, I think you can do the clean up when process starts. You can
set a flag to see if the process is exit properly. If not, check it at the
beginning of your app, and do clean up.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #3
Hi Jaans,

As far as I know, it is issuing a TerminateProcess. If so, I think you can
try to set timeout to let the ticket expire after a period of time.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #4
Hi Jaans,

I'd like to know if this issue has been resolved yet. Is there anything
that I can help. I'm still monitoring on it. If you have any questions,
please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #5

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

Similar topics

2
by: RL | last post by:
Hello Perl gurus, 1. I have a web page where I can push a button (dospawn.html). 2. This button calls a CGI script (spawnboss.cgi) 3. spawnboss.cgi calls a forking perl script (forkme.pl) 4....
3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
3
by: Pankaj | last post by:
Hi All: Is there a solution to below problem...without....restarting VS.Net 2003 so may be sometimes restarting PC. // Cannot copy assembly 'MyClient.Client' to file...
3
by: Vagabond Software | last post by:
Scenario: The end-user selects File-Save from my applications (WinForm) menu, specifies a filename, and waits waits for my app to write the contents of a dataset to an Excel workbook. The...
5
by: Paul Bergson | last post by:
I have been trying to get a process to start up and run with arguments passed to it. I have gotten close (Thanks to help from this board) but I there is a failure while I'm running this because...
4
by: Jaans | last post by:
I have a problem that relates to running "cleanup" code when an application is forcibly ended using the "End Process" of "Task Manager" (Please note that this is very different from "End Task"...
4
by: Strah | last post by:
Is there a way to catch the event of terminating the application from the the processes tab in task manager? I have created windows app, and if a user termintates the app in the task manager,...
8
by: NAdir | last post by:
Hi, thank you for your help. My VB.Net application contains a document that the user can refresh at any time. The refresh works fine and needs to loop through few datatables (hundreds of rows)....
2
by: Tom Shelton | last post by:
On 2008-04-15, DR <softwareengineer98037@yahoo.comwrote: Where are you seeing that? In the task manager? If so, then you are looking in the wrong place. Let me tell you a little something...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.