当前位置:网站首页>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); //存日志
边栏推荐
- 45padding won't open the box
- [comprehensive pen test] difficulty 4/5, classic application of line segment tree for character processing
- 解决asp.net上传文件时文件太大导致的错误
- [C topic] Li Kou 206. reverse the linked list
- sql server强行断开连接
- Copy files / folders through Robocopy
- Raft of distributed consistency protocol
- Fast-lio: fast and robust laser inertial odometer based on tightly coupled IEKF
- (original) customize a scrolling recyclerview
- I2C device driver hierarchy
猜你喜欢

LeetCode-198-打家劫舍

39 simple version of millet sidebar exercise

Syntax summary of easygui

Deployment and simple use of PostgreSQL learning

SQL优化的一些建议,希望可以帮到和我一样被SQL折磨的你

Live classroom system 05 background management system

I hope some suggestions on SQL optimization can help you who are tortured by SQL like me

"Ask every day" reentrantlock locks and unlocks

Melody + realsense d435i configuration and error resolution

Leetcode combination sum + pruning
随机推荐
[comprehensive pen test] difficulty 4/5, classic application of line segment tree for character processing
Educational codeforces round 132 (rated for Div. 2) C, d+ac automata
bridge-nf-call-ip6tables is an unknown key异常处理
About RDBMS and non RDBMS [database system]
Copy files / folders through Robocopy
Browser based split screen reading
C#,C/S升级更新
When using jetty to run items, an error is reported: form too large or form too many keys
[C题目]力扣876. 链表的中间结点
37 element mode (inline element, block element, inline block element)
没错,请求DNS服务器还可以使用UDP协议
SSM Advanced Integration
各种平台dpkg包下载地址(包括arm64)
二维数组赋初值你会几种方法?
直播课堂系统05-后台管理系统
阿里云技术专家邓青琳:云上跨可用区容灾和异地多活最佳实践
"Ask every day" briefly talk about JMM / talk about your understanding of JMM
Deployment and simple use of PostgreSQL learning
Awk from entry to earth (24) extract the IP of the instruction network card
"How to use" observer mode