Have the application restart
Have the application restart
Is there a quick way to have your application restarted.
I have some *sort of* server application, but when the user changed it's configuration through a menu entry, the entire application should restart (will refactor so it can be done internally within the program [stopping threads, closing sockets, ..]), but I was wondering if I can not just call the Exit myself, like when the user would have selected the quit/exit menu entry, but in some way have wx register the application with the OS to have it restarted automatically.
Is such a thing possible ?
I have some *sort of* server application, but when the user changed it's configuration through a menu entry, the entire application should restart (will refactor so it can be done internally within the program [stopping threads, closing sockets, ..]), but I was wondering if I can not just call the Exit myself, like when the user would have selected the quit/exit menu entry, but in some way have wx register the application with the OS to have it restarted automatically.
Is such a thing possible ?
-
- I live to help wx-kind
- Posts: 192
- Joined: Fri Dec 22, 2006 9:17 am
- Location: Germany
- Contact:
On UNIX at least, there is not need for such an helper app, the shell is your helper appmc2r wrote:Write a helper app that only waits a moment and then starts your app.
Launch it from your app, your app exits
helper app waits for your app to exit and then restarts it
helper app exits
Code: Select all
wxExecute("sleep 5 && myapp");
"Keyboard not detected. Press F1 to continue"
-- Windows
-- Windows
-
- Earned some good credits
- Posts: 103
- Joined: Sun Aug 05, 2007 5:49 am
I did something like this for make an updater for my app. It does require a help app. The parent app sends a WID command to the help app. I ripped some code out for ya to play with.
PARENT APP
HELPERAPP.h
HELPERAPP.cpp
PARENT APP
Code: Select all
wxProcess temp;
temp.Open(wxString::Format(wxT("helper.exe --WID=%d"), ::wxGetProcessId()), wxEXEC_ASYNC);
temp.Detach();
Code: Select all
#include <wx/wxprec.h>
#include <wx/cmdline.h>
#include <wx/process.h>
#include <wx/wfstream.h>
const wxCmdLineEntryDesc gCmdLineDesc[] =
{
{ wxCMD_LINE_OPTION, wxT("id"), wxT("WID"), wxT("Windows Process ID"), wxCMD_LINE_VAL_NUMBER },
{ wxCMD_LINE_NONE }
};
/////////////////////////////////////////////////////////////////////////////////
class MyApp : public wxApp
{
public:
virtual bool OnInit();
virtual int OnRun(){::wxExit(); return 0;}
virtual void OnInitCmdLine(wxCmdLineParser& parser);
virtual bool OnCmdLineParsed(wxCmdLineParser& parser);
private:
DECLARE_NO_COPY_CLASS(MyApp)
};
DECLARE_APP(MyApp)
#endif //APP_H
HELPERAPP.cpp
Code: Select all
//// App.cpp ////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
#include "App.h"
IMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
if ( !wxApp::OnInit() ) return false;
}
void MyApp::OnInitCmdLine(wxCmdLineParser& parser)
{
parser.SetDesc (gCmdLineDesc);
parser.SetSwitchChars (wxT("-"));
}
bool MyApp::OnCmdLineParsed(wxCmdLineParser& parser)
{
parser.Parse();
long value;
//We got a command to close eTrigger
if(parser.Found(wxT("WID"), &value)){
if(wxProcess::Exists(value)){
//Okay, then let's close parent.exe
int killError = wxProcess::Kill(value, wxSIGTERM);
if(killError){
if(killError == wxKILL_BAD_SIGNAL){msg = wxT("wxProcess::Kill Error: no such signal"); return true;}
if(killError == wxKILL_ACCESS_DENIED){msg = wxT("wxProcess::Kill Error: permission denied"); return true;}
if(killError == wxKILL_NO_PROCESS){msg = wxT("wxProcess::Kill Error: no such process"); return true;}
if(killError == wxKILL_ERROR){
wxMessageBox(wxT("An Error occured attempting to close parent.exe, the helper will now attempt to forcefully close parent.exe"));
int killError2 = wxProcess::Kill(value, wxSIGKILL);
if(killError2){
msg = wxT("The Helper could not close parent.exe"); return true;
}
}
}
//Now let's open the parent
wxProcess temp;
temp.Open(wxT("parent.exe"), wxEXEC_ASYNC | wxEXEC_NOHIDE);
temp.Detach();
Exit();
}
-
- Earned a small fee
- Posts: 22
- Joined: Wed Oct 05, 2005 1:24 pm
You can also do something like "internal restart" that I have used in couple of my applications. All you need to do is to create empty and hidden top frame which will start your main classes. When you need to restart just call restart method in your hidden frame that will destroy all child frames, dialogs, threads, processes etc. and start them again.