質問

I'm using the CreateProcess API with the CREATE_NEW_CONSOLE option, since I want the app to be opened in a new window. When I call TerminateProcess, it doesn't close the window right away, but rather with a delay. Is it possible to somehow force it to close the window straight away?

I'm currently running on Windows7 64bit, but the program I'm working on shouldn't be dependent on the WIN version.

I wanted to use CREATE_NEW_CONSOLE so that the main window won't be hijacked by the new application.

役に立ちましたか?

解決

I tried to reproduce the issue with CREATE_NEW_CONSOLE flag.

STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
TCHAR szCommand[MAX_PATH];
_sntprintf_s(szCommand, MAX_PATH, _T("%s"), _T("c:\\windows\\system32\\cmd.exe"));
DWORD res = CreateProcess(NULL, szCommand, NULL, NULL, FALSE, 
                          CREATE_NEW_CONSOLE, 
                          NULL, NULL, &si, &pi);
TerminateProcess(pi.hProcess, NULL);

No delays in termination process.

enter image description here

Try use procmon to figure out where delay occur in your case.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top