We have successfully been using wxSingleInstanceChecker in combination with the Win32 API RegisterApplicationRestart() to relaunch our wxWidgets application after crashes. However, we just found that Application Restart is no longer working. The problem has been tracked down to the wxSingleInstanceChecker saying the application is still running.
1) In the application's OnInit() handler a wxSingleInstanceChecker object is created
2) with that wxSingleInstanceChecker object, mp_singleInstChecker->IsAnotherRunning() is called.
Under a normal application launch, the IsAnotherRunning() test fails and the application proceeds to create the main window and launch.
After an application crash, when the IsAnotherRunning() test says another is already running, I've tried adding a delay and asking again... but after as much as a 20 second delay, calling IsAnotherRunning() from that same wxSingleInstanceChecker object is still returning "true".
It appears a new/different wxSingleInstanceChecker object needs to be created? I just tried adding the creation of a different wxSingleInstanceChecker object after my delay, and it confirms no other version is running. Any idea why or when this changed? Is this even correct, or does something smell fishy with this solution?
Code: Select all
bool Aureus3Dv ::OnInit()
{
mp_singleInstChecker = new wxSingleInstanceChecker;
if ( mp_singleInstChecker->IsAnotherRunning() )
{
// our crashed version might still be writing a crash recovery, give it time to complete:
wxSleep(20); // it only needs 1 second, but why is this returning true even after this long delay?
delete mp_singleInstChecker;
mp_singleInstChecker = new wxSingleInstanceChecker; // make a completely new instance?
if ( mp_singleInstChecker->IsAnotherRunning() )
{
wxMessageBox( "Multiple instances of this application were launched, this instance is auto-terminating!",
wxT(APP_NAME_LONG), wxOK | wxICON_EXCLAMATION, NULL );
return false;
}
}
mp_mainframe = new Aureus3DvMainFrame();
mp_mainframe->Show(true);
return true;
}
/* Cleanup for Aureus3Dv */
int Aureus3Dv ::OnExit() {
if (mp_singleInstChecker)
{
delete mp_singleInstChecker;
mp_singleInstChecker = NULL;
}
return wxApp::OnExit();
}