Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous messageGo to previous message
lectus is currently offline  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.
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: TopWindow minimum size
Next Topic: Timeout on PromptYesNo?
Goto Forum:
  


Current Time: Wed May 08 22:29:01 CEST 2024

Total time taken to generate the page: 0.03029 seconds