Hello,
I have a GUI with two buttons. Button "Execute" calls the following piece of code (processHandle is a global HANDLE):
ExecCmd::Run()
{
STARTUPINFO start;
PROCESS_INFORMATION pinfo;
memset(&start, 0, sizeof(STARTUPINFO));
start.cb = sizeof(start);
DWORD returnValue;
long time = 100;
returnValue =
CreateProcess(NULL, "C:\\Butterfly\\Butterfly.exe",
0, 0, TRUE, IDLE_PRIORITY_CLASS, 0, 0, &start, &pinfo);
processHandle = &(pinfo.hProcess);
do{
returnValue = WaitForSingleObject(pinfo.hProcess, time);
if (returnValue < 0) break;
DoEvents();
} while (returnValue != 0);
GetExitCodeProcess(pinfo.hProcess, &returnValue);
CloseHandle(pinfo.hProcess);
}
Another GUI Button "Abort" calls a function which uses the global handle to terminate the process:
TerminateProcess(processHandle, 1);
The PROBLEM I am having is that
1)Seems like the process is eating resources and the OS becomes quite slughish!!! The .exe in CreateProcess is a simple one which causes no problem at all outside this function.
2) The TerminateProcess does not work at all!
What am I doing wrong??
I have a GUI with two buttons. Button "Execute" calls the following piece of code (processHandle is a global HANDLE):
ExecCmd::Run()
{
STARTUPINFO start;
PROCESS_INFORMATION pinfo;
memset(&start, 0, sizeof(STARTUPINFO));
start.cb = sizeof(start);
DWORD returnValue;
long time = 100;
returnValue =
CreateProcess(NULL, "C:\\Butterfly\\Butterfly.exe",
0, 0, TRUE, IDLE_PRIORITY_CLASS, 0, 0, &start, &pinfo);
processHandle = &(pinfo.hProcess);
do{
returnValue = WaitForSingleObject(pinfo.hProcess, time);
if (returnValue < 0) break;
DoEvents();
} while (returnValue != 0);
GetExitCodeProcess(pinfo.hProcess, &returnValue);
CloseHandle(pinfo.hProcess);
}
Another GUI Button "Abort" calls a function which uses the global handle to terminate the process:
TerminateProcess(processHandle, 1);
The PROBLEM I am having is that
1)Seems like the process is eating resources and the OS becomes quite slughish!!! The .exe in CreateProcess is a simple one which causes no problem at all outside this function.
2) The TerminateProcess does not work at all!
What am I doing wrong??