当前位置:网站首页>Basic usage of MFC thread afxbeginthread, passing multiple parameters
Basic usage of MFC thread afxbeginthread, passing multiple parameters
2022-07-25 15:54:00 【sam-zy】
UI Threads :
CWinThread* AFXAPI AfxBeginThread(
CRuntimeClass* pThreadClass, // from CWinThread Derived RUNTIME_CLASS class
int nPriority, // Specify thread priority , If 0, Is the same as the thread that created the thread
UINT nStackSize, // Specifies the stack size of the thread , If 0, Is the same as the thread that created the thread
DWORD dwCreateFlags,// Create logo If it is CREATE_SUSPENDED The thread is created in the suspended state , Thread suspended after thread creation , Otherwise, the thread starts executing after it is created
LPSECURITY_ATTRIBUTES lpSecurityAttrs)// Thread security properties ,NT Next useful .
Worker threads :
CWinThread* AfxBeginThread(AFX_THREADPROC pfnThreadProc,// Entry function , Statement :UINT MyThreadFunction(LPVOID pParam)
LPVOID lParam, // Parameters passed into the thread , Its type is :LPVOID, So you can pass a structure into the thread
int nPriority = THREAD_PRIORITY_NORMAL, // Thread priority , Generally set as 0 . Let it have the same priority as the main thread .
UINT nStackSize = 0, // Specify the stack size of the newly created thread . If 0, The newly created thread has a stack the same size as the main thread
DWORD dwCreateFlags = 0, //CREATE_SUSPENDED: After the thread is created , Will be suspended , Until the call :ResumeThread
//0: Start running after creating the thread .
LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL // If NULL, Then the newly created thread has the same security as the main thread .
); // Return value : When successful, it returns a pointer to the thread object of the new thread , otherwise NULL.
Thread priority :https://blog.csdn.net/zhengyanan815/article/details/53786639
Worker threads use :
1. Passing in a single parameter
1. Thread handler
void* Camera::CodeSaveThread(void* pParam)
{
CString Codes = *(CString*)pParam; // The typeless pointer becomes an integer pointer
//...
//...
AfxEndThread(0);
return 0;
}
2. Start a thread :
CString Code = _T("test");
AfxBeginThread((AFX_THREADPROC)CodeSaveThread, (void*)&Code, THREAD_PRIORITY_IDLE); // Keep a log
2. Pass multiple parameters ( Structure )
1. Thread handler
struct LogStruct // Save log structure
{
CString LogName;
CString DataStr;
};
void* Camera::CodeSaveThread(void* pParam)
{
LogStruct LogStru = *(LogStruct*)pParam; // The typeless pointer becomes an integer pointer
CString LogName = LogStru.LogName ;
CString Codes = LogStru.DataStr;
//...
//...
AfxEndThread(0);
return 0;
}
2. Start a thread :
CString Code = _T("test");
LogStruct LogStru;
LogStru.LogName = _T("Log");
LogStru.DataStr = Code;
AfxBeginThread((AFX_THREADPROC)CodeSaveThread, (void*)&LogStru, 0); // Keep a log
边栏推荐
- Reasons for data format conversion when matlab reads the displayed image
- Understanding of this object
- Brain racking CPU context switching
- LeetCode - 362 敲击计数器(设计)
- Circulaindicator component, which makes the indicator style more diversified
- 2600 pages in total! Another divine interview manual is available~
- Matlab -- CVX optimization kit installation
- 华为2023届提前批预热开始!左 神的程序代码面试指南终派上用场
- Leetcode - 379 telephone directory management system (Design)
- 2021 Shanghai match-h-two point answer
猜你喜欢

Gary Marcus: 学习语言比你想象的更难

Alibaba's internal "100 billion level concurrent system architecture design notes" are all inclusive, too comprehensive

Pytorch学习笔记-Advanced_CNN(Using Inception_Module)实现Mnist数据集分类-(注释及结果)

十字链表的存储结构

LeetCode - 379 电话目录管理系统(设计)

MySQL—常用SQL语句整理总结

不愧是阿里内部“千亿级并发系统架构设计笔记”面面俱到,太全了

LeetCode - 380 O(1) 时间插入、删除和获取随机元素 (设计 哈希表+数组)

JVM - classloader and parental delegation model

HDD Hangzhou station · harmonyos technical experts share the features of Huawei deveco studio
随机推荐
MySQL教程71-WHERE 条件查询数据
Geogle colab notes 1-- run the.Py file on the cloud hard disk of Geogle
Is there only one lib under JDBC in Seata?
LeetCode - 359 日志速率限制器 (设计)
LeetCode - 379 电话目录管理系统(设计)
兆骑科创海内外高层次创新创业人才服务平台,双创成果转化平台
Gary marcus: learning a language is more difficult than you think
Baseband simulation system experiment of 4pam in Gaussian channel and Rayleigh channel
2016 CCPC network trial c-change root DP good question
MySQL教程67-使用DISTINCT过滤重复数据
How matlab saves all the data after running
Beyond Compare 4 实现class文件对比【最新】
Pytorch学习笔记-Advanced_CNN(Using Inception_Module)实现Mnist数据集分类-(注释及结果)
Pytoch learning notes -- Summary of common functions of pytoch 1
MySQL教程65-MySQL操作表中数据
Window system black window redis error 20creating server TCP listening socket *: 6379: listen: unknown error19-07-28
ZOJ - 4114 flipping game DP, reasonable state representation
2019 Zhejiang race c-wrong arrangement, greedy
Geogle Colab笔记1--运行Geogle云端硬盘上的.py文件
Brain racking CPU context switching