Home > Software engineering >  How to realize the delay resumption of MFC software development?
How to realize the delay resumption of MFC software development?

Time:09-24

I need to use the software to restart in the development of software, but software exits some cleanup work slowly, restart needs to wait for clear memory is complete restart again? How to implement, thank you!

At present is to reopen the CreateProcess software exit call software, but the reality is that sometimes in front of the open software software also not clear!

 char pbufs [MAX_PATH]; 
//the application completely path, more than the GetCurrentDirectory to use
GetModuleFileName (NULL, pbufs MAX_PATH);

STARTUPINFO STARTUPINFO;
PROCESS_INFORMATION proc_info;
Memset (& amp; Startupinfo, 0, sizeof (startupinfo));
Startupinfo. Cb=sizeof (startupinfo);
The most important place in the//
If (TRUE) : : CreateProcess (pbufs, NULL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, & amp; Startupinfo, & amp; Proc_info);

CodePudding user response:

You can wait for all the cleanup completed calls CreateProcess!
Otherwise had to write a service with monitoring the current application status until complete withdrawal from him to restart again

CodePudding user response:

Software exit before the call to create a global naming or mutually exclusive events, to prompt, clear the end, in the final exits closed named events/mutex another startup process open when detecting the signal events/mutex
Exist, exit and wait for the previous software

CodePudding user response:

This isn't just turn off the window, clean up the work in process, finished cleaning up and then open the window

CodePudding user response:

CreateProcess create a restart process, however, you must use a process share the synchronization object to control whether close to complete, the synchronization objects when entering the program to create immediately, at the end of the program, then shut down,

CodePudding user response:

With the kernel mutex object CreateMutex can

CodePudding user response:

Using a different program to do judgment and start

 
//ExeRestart. CPP
//

# include "stdafx. H"
#include
#include
#include
#include
#include
#include
#include
# pragma comment (lib, "Shlwapi. Lib")

BOOL FoundProcess (DWORD dwProcessID)
{
BOOL bRet=FALSE;
HANDLE hProcessSnap=NULL;

HProcessSnap=CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
If (hProcessSnap!=INVALID_HANDLE_VALUE)
{
PROCESSENTRY32 pe32={sizeof (PROCESSENTRY32)};
BOOL bWorking=Process32First (hProcessSnap, & amp; Pe32);

While (bWorking)
{
If (dwProcessID==pe32. Th32ProcessID)
{
BRet=TRUE;
}

BWorking=Process32Next (hProcessSnap, & amp; Pe32);
}

The CloseHandle (hProcessSnap);
}

Return (bRet);
}

//
//ExeRestart/PID=waiting for the end of the PID/EXE=start EXE program

Int _tmain (int arg c, TCHAR * argv [])
{
Int iRet=0;
LPCTSTR szApp=PathFindFileName (argv [0]).
LPCTSTR szPID=NULL, szExe=NULL;

if(argc !
=3){
_tprintf (_T (" Using % s/PID=1234/EXE=aa. EXE \ n "), szApp);
}
The else
{
SzPID=argv [1] + 5;
SzExe=argv [2] + 5;

DWORD dwPID=_tcstoul (szPID, NULL, 10);

If (dwPID!=GetCurrentProcessId ())
{
While (FoundProcess (dwPID))
{
Sleep (1000);
}

ShellExecute iRet=(int), NULL, NULL, szExe, NULL, NULL, SW_SHOWNORMAL);
}
}

Return iRet;
}



CodePudding user response:

The basic function of the kernel object,

CodePudding user response:

Sleep is finished

CodePudding user response:

Clean up before you start another program start the program, and then sort the program window is not hidden with respect to OK
  • Related