在MFC中停止正在运行的线程 [英] Stop a running thread in mfc
本文介绍了在MFC中停止正在运行的线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对线程有一些疑问.
我需要使用主窗口中的线程来调用函数,并且函数执行进度应返回到对话框.当按下对话框上的取消"按钮时,线程必须停止执行.
任何人都可以解决这个问题吗?
Hi,
I have some queries on threading.
I need to call a function using a thread from the main window and function execution progress should be returned to a dialog. When the "Cancel" button on the dialog is pressed, the thread must stop execution.
Can anyone solve this problem???
推荐答案
DWORD exit_code= NULL;
if (thread != NULL)
{
GetExitCodeThread(thread->m_hThread, &exit_code);
if(exit_code == STILL_ACTIVE)
{
::TerminateThread(thread->m_hThread, 0);
CloseHandle(thread->m_hThread);
}
thread->m_hThread = NULL;
thread = NULL;
}
这篇关于在MFC中停止正在运行的线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文