Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a desktop application in C# which needs to be running at all times. But some one closes the application. I can not find out at what time the application is closed using the TASK MANAGER ? I need to find the system event logs or anything similar(no external application) which shows when the application started and when it was closed. Thanks in advance
Posted

Use Timer[^] and write the application status on every minute or 5 minutes... to a text file or database.
ref:
http://social.msdn.microsoft.com/Forums/windows/en-US/43daf8b2-67ad-4938-98f7-cae3eaa5e63f/how-to-use-timer-control-in-c?forum=winforms[^]
 
Share this answer
 
Comments
Oliver Bleckmann 24-May-14 6:24am    
certainly possible, kind like a heartbeat implementation. Or, depending on what you consider an "external application", just the other way round, use a loader or monitor (e.g. as a windows service) like "pinging your application" to see if it is still there and responding. This way you could even tell if it freezes for some time. Maybe you can spawn a decoupled task for this job. hope this helps.
What i would do is using the main form closing event to write in a txt file the time when it is closing and the form load or the constructor to write when it starts. This way you'll have a log with times of start/stop.
 
Share this answer
 
Comments
Hassan(Aych Jay) 23-May-14 3:19am    
I have a log like this maintained, but some how when the application is forced closed there is no record of it to be found. I am sure that the application is forced closed. That's why i am stuck.
Pikoh 23-May-14 3:35am    
Then the only solution i can think of is the one DamithSL told use..use a timer to write the log every x minutes so you can more or less guess when was it closed.
Hassan(Aych Jay) 23-May-14 6:10am    
A log file is maintained. I wanted to find the exact time so that i could use that time later for calculations. It is a monitoring application so i want it to be exact :)
When your application starts, write the time to a file. Then use Application.ApplicationExit event to notice the time when it closes.
http://msdn.microsoft.com/en-us/library/system.windows.forms.application.applicationexit(v=vs.110).aspx[^]
 
Share this answer
 
Comments
Hassan(Aych Jay) 26-May-14 2:35am    
I have tried the Application.ApplicationExit event handler. When i end task the process it just closes it and the event is not triggered at all. I want to catch this time since its important for break management

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900