Home » U++ Library support » TopWindow&PopUp, TrayIcon » How to check whether application is running
Re: How to check whether application is running [message #38789 is a reply to message #38772] |
Fri, 18 January 2013 01:56 |
lectus
Messages: 329 Registered: September 2006 Location: Brazil
|
Senior Member |
|
|
Alboni wrote on Wed, 16 January 2013 09:44 | Yes, I've seen a number of programs that do just that. Moest of them were on linux.
Disadvantage is that the program doesn't want to start anymore after a crash, and then an admin has to come who knows where that file is located and delete the file.
That could also be feature btw, if the program also checks for the existance of an application window or mutex to determine if it was a crash or a double start and then can take special measures in case of a crash such as rebuilding a databaseindex, submit a crash report or restoring the state of the program.
|
void ChangeStatus() {
SaveFile(GetExeDirFile("lock"), "Finished succesfully");
}
if(!FileExists(GetExeDirFile("lock")))
SaveFile(GetExeDirFile("lock"), "Finished sucessfully");
String status = LoadFile(GetExeDirFile("lock"));
if(status == "running")
{
Exclamation("There's another instance!");
return;
}
if(status == "crashed") {
Exclamation("The program crashed on the last run. Please restart the application.");
RecoverData();
ChangeStatus();
return;
}
SaveFile(GetExeDirFile("lock"), "running");
atexit(ChangeStatus);
Before critical part of the program:
SaveFile(GetExeDirFile("lock"), "crashed");
DoLongOperations(); // if it crashes now we're safe
SaveFile(GetExeDirFile("lock"), "running"); // We survived
If you want to get fancy, add time stamps.
|
|
|
|
|
How to check whether application is running
By: bushman on Mon, 09 August 2010 03:59
|
|
|
Re: How to check whether application is running
By: bushman on Mon, 09 August 2010 04:16
|
|
|
Re: How to check whether application is running
|
|
|
Re: How to check whether application is running
By: bushman on Mon, 09 August 2010 05:18
|
|
|
Re: How to check whether application is running
|
|
|
Re: How to check whether application is running
By: unodgs on Tue, 10 August 2010 22:47
|
|
|
Re: How to check whether application is running
By: kohait00 on Fri, 13 August 2010 16:21
|
|
|
Re: How to check whether application is running
By: Alboni on Wed, 16 January 2013 12:29
|
|
|
Re: How to check whether application is running
By: lectus on Wed, 16 January 2013 14:38
|
|
|
Re: How to check whether application is running
By: Alboni on Wed, 16 January 2013 15:44
|
|
|
Re: How to check whether application is running
|
|
|
Re: How to check whether application is running
By: lectus on Fri, 18 January 2013 01:56
|
|
|
Re: How to check whether application is running
|
|
|
Re: How to check whether application is running
By: Alboni on Wed, 16 January 2013 17:38
|
|
|
Re: How to check whether application is running
By: Alboni on Wed, 16 January 2013 18:01
|
|
|
Re: How to check whether application is running
By: BioBytes on Wed, 16 January 2013 21:32
|
Goto Forum:
Current Time: Wed May 08 22:29:01 CEST 2024
Total time taken to generate the page: 0.03029 seconds
|