如何中断正在执行 DOS命令行 的线程?
这是我的代码, 怎么停止它?
//-------------------------------
cmd = "cmd.exe /c xxxxx ";//调用dos命令,可能执行很长时间
Create_Process(cmd,false);
void Create_Process(char* cmd, BOOL async)//超线程代码
{
HANDLE hProcess;
HANDLE hThread;
PROCESS_INFORMATION PI;
STARTUPINFO SI;
memset(&SI, 0, sizeof(SI));
SI.cb = sizeof(SI);
GetStartupInfo(&SI);
SI.wShowWindow=SW_HIDE;
SI.dwFlags=1;
CreateProcess(NULL,temp_exe, NULL, NULL, true,CREATE_NEW_CONSOLE, NULL, NULL, &SI, &PI);
hProcess = PI.hProcess;
hThread = PI.hThread;
if (!async)WaitForSingleObject(hProcess, INFINITE);
}
[解决办法]
暂停它的主线程SuspendThread(PI-> hThread)
[解决办法]
if(MyThread!=NULL)
{
MyThread-> Terminate();
DWORD dwExitCode;
GetExitCodeThread( (void *)MyThread-> Handle ,&dwExitCode) ;
if(dwExitCode == STILL_ACTIVE )
TerminateThread( (void *)MyThread-> Handle, dwExitCode);
MyThread = NULL;
}