I would like to implement a safe "CloseAndRestartWhenYouCan" routine into my project. The project is running several wxTimer-Loops, so I had some issues before when closing the app, because a timer-loop may still be doing fancy things.
I thought about a routine which wouldn't allow a timer to re-Start(), when an app-restart is requested so they could finish the work before closing. (I stop my timers before doing the work and usually restart them after it).
I derived wxTimer for that purpose to intercept the Start() function, which is ok.
Code: Select all
bool MyTimer::Start(int milli, bool oneShot)
{
try
{
if (!wxGetApp().SetForSecureRestart())
{
return wxTimer::Start(milli, oneShot);
}
}
catch (...)
{
return wxTimer::Start(milli, oneShot);
}
return true;
}
Code: Select all
bool MyApp::SetForSecureRestart()
{
bool bRestart = true;
if (mb_secureAppRestart)
{
try
{
if (m_frame->mt_GOtimer->IsRunning())
{
bRestart = false;
}
if (m_frame->mt_notifTimer->IsRunning())
{
bRestart = false;
}
if (m_frame->mt_settingsTimer->IsRunning())
{
bRestart = false;
}
if (m_frame->m_watchfolder->IsRunning())
{
bRestart = false;
}
}
catch (...)
{
}
}
if (bRestart && mb_secureAppRestart)
{
RestartApp(false);
}
return mb_secureAppRestart;
}
Code: Select all
MyFrame::~MyFrame()
{
try
{
mt_GOtimer->Stop();
...
-->wxDELETE(mt_GOtimer);
...
Code: Select all
wxTimer::~wxTimer()
{
-->Stop();
delete m_impl;
}
Code: Select all
if (__abort_behavior & _CALL_REPORTFAULT)
{
#if defined _M_ARM || defined _M_ARM64
__fastfail(FAST_FAIL_FATAL_APP_EXIT);
#else
if (IsProcessorFeaturePresent(PF_FASTFAIL_AVAILABLE))
--> __fastfail(FAST_FAIL_FATAL_APP_EXIT);
__acrt_call_reportfault(_CRT_DEBUGGER_ABORT, STATUS_FATAL_APP_EXIT, EXCEPTION_NONCONTINUABLE);
#endif
}
Or do you know a better way to solve my restart issue?
Have a nice day
Natu