当前位置:网站首页>MFC 线程AfxBeginThread基本用法,传多个参数
MFC 线程AfxBeginThread基本用法,传多个参数
2022-07-25 14:59:00 【sam-zy】
UI线程:
CWinThread* AFXAPI AfxBeginThread(
CRuntimeClass* pThreadClass, //从CWinThread派生的RUNTIME_CLASS类
int nPriority, //指定线程优先级,如果为0,则与创建该线程的线程相同
UINT nStackSize, //指定线程的堆栈大小,如果为0,则与创建该线程的线程相同
DWORD dwCreateFlags,//创建标识 如果是CREATE_SUSPENDED 则在悬挂状态创建线程,在线程创建后线程挂起,否则线程在创建后开始线程的执行
LPSECURITY_ATTRIBUTES lpSecurityAttrs)//线程的安全属性,NT下有用。
工作者线程:
CWinThread* AfxBeginThread(AFX_THREADPROC pfnThreadProc,//入口函数,声明:UINT MyThreadFunction(LPVOID pParam)
LPVOID lParam, //传递入线程的参数,它的类型为:LPVOID,所以可以传递一个结构体入线程
int nPriority = THREAD_PRIORITY_NORMAL, //线程的优先级,一般设置为 0 .让它和主线程具有共同的优先级.
UINT nStackSize = 0, //指定新创建的线程的栈的大小.如果为 0,新创建的线程具有和主线程一样的大小的栈
DWORD dwCreateFlags = 0, //CREATE_SUSPENDED:线程创建以后,会处于挂起状态,直到调用:ResumeThread
//0:创建线程后就开始运行.
LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL //如果为 NULL,那么新创建的线程就具有和主线程一样的安全性.
); //返回值: 成功时返回一个指向新线程的线程对象的指针,否则NULL。
线程优先级:https://blog.csdn.net/zhengyanan815/article/details/53786639
工作者线程使用:
1.传入单个参数
1.线程处理函数
void* Camera::CodeSaveThread(void* pParam)
{
CString Codes = *(CString*)pParam; //无类型指针变为整形数指针
//...
//...
AfxEndThread(0);
return 0;
}
2.启动一个线程:
CString Code = _T("test");
AfxBeginThread((AFX_THREADPROC)CodeSaveThread, (void*)&Code, THREAD_PRIORITY_IDLE); //存日志
2.传多个参数(结构体)
1.线程处理函数
struct LogStruct //存日志结构体
{
CString LogName;
CString DataStr;
};
void* Camera::CodeSaveThread(void* pParam)
{
LogStruct LogStru = *(LogStruct*)pParam; //无类型指针变为整形数指针
CString LogName = LogStru.LogName ;
CString Codes = LogStru.DataStr;
//...
//...
AfxEndThread(0);
return 0;
}
2.启动一个线程:
CString Code = _T("test");
LogStruct LogStru;
LogStru.LogName = _T("Log");
LogStru.DataStr = Code;
AfxBeginThread((AFX_THREADPROC)CodeSaveThread, (void*)&LogStru, 0); //存日志
边栏推荐
- LeetCode-198-打家劫舍
- 37 元素模式(行内元素,块元素,行内块元素)
- Examples of bio, NiO, AIO
- Yes, UDP protocol can also be used to request DNS server
- Yarn: the file yarn.ps1 cannot be loaded because running scripts is prohibited on this system.
- 27 classification of selectors
- PHP implements non blocking (concurrent) request mode through native curl
- 35 quick format code
- kibana操作es
- easygui使用的语法总结
猜你喜欢

Melody + realsense d435i configuration and error resolution

【MySQL系列】-索引知多少

IP地址分类,判断一个网段是子网超网

"Ask every day" how locksupport realizes thread waiting and wakeup

37 element mode (inline element, block element, inline block element)

Heyuan City launched fire safety themed milk tea to boost fire prevention and control in summer

LeetCode-198-打家劫舍

pl/sql 创建并执行oralce存储过程,并返回结果集

ESXI6.7.0 升级到7.0U3f(2022年7月12 更新)

Unable to start web server when Nacos starts
随机推荐
[nuxt 3] (XI) transmission & module
Leetcode-198- house raiding
Leo-sam: tightly coupled laser inertial odometer with smoothing and mapping
"Ask every day" what is volatile
Educational codeforces round 132 (rated for Div. 2) C, d+ac automata
流程控制(上)
bridge-nf-call-ip6tables is an unknown key异常处理
27 classification of selectors
Awk from getting started to digging in (23) awk built-in variables argc, argc -- command line parameter transfer
Quickly set up dobbo demo
[MySQL series] - how much do you know about the index
Yarn: the file yarn.ps1 cannot be loaded because running scripts is prohibited on this system.
Awk from getting started to digging in (20) awk parsing command line parameters
[C题目]力扣88. 合并两个有序数组
006 operator introduction
Thymeleaf notes
SSM Advanced Integration
Spark 参数配置的几种方法
Ssh server rejected password
[C题目]牛客 链表中倒数第k个结点