multithreading - 如何知道代码是在 ui 线程还是工作线程上运行 (MFC Visual C++)

标签 multithreading visual-c++ mfc user-interface

我有一个从应用程序中的不同线程调用的函数。 我需要知道执行代码的线程是主线程(ui线程)还是工作线程。

有什么建议吗?

谢谢。

最佳答案

如果您使用的是 MFC 应用程序,请使用以下代码。

if(GetCurrentThreadId() == AfxGetApp()->m_nThreadID)
{
    //Main Thread
}
else
{
    //Not Main Thread
}

关于multithreading - 如何知道代码是在 ui 线程还是工作线程上运行 (MFC Visual C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/914646/

相关文章:

C++ 和 SDL : Why can't I compile this program?

c++ - 如何在 MFC 中获得多行工具提示

c++ - 调用 SetEvent 后调用 CloseHandle

c++ - 我可以重载 CArchive << 运算符以使用 std::string 吗?

multithreading - 如何在一台服务器上配置Elasticsearch集群以获得最佳搜索性能

java - 有没有更理想的发送绘图命令的方式?

c++ - 为什么成员函数尝试 block 处理程序中的 lambda(捕获 'this')不能访问 VC++ 2013 中的私有(private)数据成员?

多线程中的Python单元测试

c - 我如何跟踪所有 fork()

c++ - this->... 在模板包装器类中需要