当前位置:网站首页>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
边栏推荐
- Are you ready to break away from the "involution circle"?
- PAT甲级1152 Google Recruitment (20 分)
- 2021 Jiangsu race a Array line segment tree, maintain value range, Euler power reduction
- 微信小程序
- Leetcode - 677 key value mapping (Design)*
- LeetCode - 677 键值映射(设计)*
- P4552 differential
- I want to ask whether the variable configuration function can only be used in SQL mode
- 兆骑科创海内外高层次创新创业人才服务平台,双创成果转化平台
- Data system partition design - partition rebalancing
猜你喜欢

活动回顾|7月6日安远AI x 机器之心系列讲座第2期|麻省理工教授Max Tegmark分享「人类与AI的共生演化 」

Circulaindicator component, which makes the indicator style more diversified

JVM knowledge brain map sharing

JVM—类加载器和双亲委派模型

Solve the vender-base.66c6fc1c0b393478adf7.js:6 typeerror: cannot read property 'validate' of undefined problem

Leetcode - 677 key value mapping (Design)*

Brain racking CPU context switching

LeetCode - 359 日志速率限制器 (设计)

MySQL—常用SQL语句整理总结

Leetcode - 362 knock counter (Design)
随机推荐
LeetCode - 641 设计循环双端队列(设计)*
Pytoch learning notes advanced_ CNN (using perception_module) implements MNIST dataset classification - (comments and results)
Pytorch学习笔记--SEResNet50搭建
2016 CCPC network trial c-change root DP good question
【服务器数据恢复】HP EVA服务器存储意外断电导致RAID信息丢失的数据恢复案例
How Google cloud disk is associated with Google colab
Data system partition design - Request Routing
Cf750f1 thinking DP
Activity review | July 6 Anyuan AI X machine heart series lecture No. 2 | MIT professor Max tegmark shares "symbiotic evolution of human and AI"
I want to ask whether the variable configuration function can only be used in SQL mode
Games101 review: 3D transformation
Cf888g clever dictionary tree + violent divide and conquer (XOR minimum spanning tree)
Beyond compare 4 realizes class file comparison [latest]
Gary Marcus: 学习语言比你想象的更难
Pytoch learning notes - Teacher Liu Er RNN advanced chapter - code comments and results
Deadlock gossip
2021hncpc-e-difference, thinking
BSC smart chain contract mode system development details
微信小程序
Leetcode - 707 design linked list (Design)