Thread and Event
来源:互联网 发布:asp编程入门 编辑:程序博客网 时间:2024/05/17 06:04
近來在處理一些Serial port的問題,打算將讀取data的程式做成thread,減少主線程被佔住的時間,發現使用Event與Thread配合,還挺不錯用的,方式如下:
先定義一個 event的 HANDLE
HANDLE m_hReadEvent;
在MFC的OnInitialDlg() Create他
// CreateEvent第一個參數可以不設定,第二個參數為是否使用手動設定Event 的Signal,第三個參數是設定初始值,第四個參數是Alias name
m_hReadEvent = CreateEvent(NULL, true, false, NULL);
在要讀取資料前設定Event的signal
SetEvent(m_hReadEvent);
在Thread裡用
WaitForSingleObject(m_hReadEvent, INFINITE) == WAIT_OBJECT_0去判斷Signal是否Enable,是的話就接收buffer的資料,並將Event的signal disable。
ResetEvent(m_hReadEvent);
若要讓Thread一直跑,就使用while(1)的迴圈去跑就可以了。
- Thread and Event
- main and the GUI Event Dispatch Thread
- main and the GUI Event Dispatch Thread
- ActiveX, Second Thread, Event
- zk event thread model
- The Event-Dispatching Thread
- PreviewXXX event and XXX event
- Event Manager and Event Listener
- 软件架构thread和Event
- Thread Id and Thread Handle
- Java and event handling
- DELEGATE AND EVENT
- HRESULT and Event
- Hibernate Interceptor and Event
- onbeforeunload and onunload event
- Routed event and command
- About Delegate and Event
- CUDA ---- Stream and Event
- 韩顺平_php从入门到精通_视频教程_第12讲_通配符选择器_父子选择器_学习笔记_源代码图解_PPT文档整理
- 简洁的C代码: 字符串反转
- C# DataSet的使用
- 类 - 3【C++ Primer 学习笔记 - 第十二章】
- ubuntu下source、sh、bash、./执行脚本的区别
- Thread and Event
- dwr spring整合
- vs2010远程调试,设置共享文件夹
- 阿里云,促销首战失利
- cmd中运行带有main函数的java类(不需要文件目录)
- define、const&inline
- Eclipse 如何重新编译程序
- fedora下安装新字体:微软雅黑和consola字体
- 飞机加油问题