472,347 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,347 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 1885
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....
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...
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...
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...
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...
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...
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...
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...
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...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

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.