线程函数中如何实现计时器? 在线程函数中如何实现计时器?我的线程函数工作者线程,并没有消息循环,设置了计时器如何控制线程函数? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 #include <windows.h>#include <stdio.h>#include <conio.h>unsigned long WINAPI Thread(PVOID pvoid);void main(){ DWORD dwThreadId; printf("use timer in workthread of console application<masterz>\n"); HANDLE hThread = CreateThread( NULL, // no security attributes 0, // use default stack size Thread, // thread function 0, // argument to thread function 0, // use default creation flags &dwThreadId); DWORD dwwait=WaitForSingleObject(hThread,1000*30); switch(dwwait) { case WAIT_ABANDONED: printf("main thread WaitForSingleObject return WAIT_ABANDONED\n"); break; case WAIT_OBJECT_0: printf("main thread WaitForSingleObject return WAIT_OBJECT_0\n"); break; case WAIT_TIMEOUT: printf("main thread WaitForSingleObject return WAIT_TIMEOUT\n"); break; } CloseHandle(hThread); _getch();}unsigned long WINAPI Thread(PVOID pvoid){ MSG msg; PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE); UINT timerid=SetTimer(NULL,111,3000,NULL); BOOL bRet; int count =0; while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0) { if (bRet == -1) { // handle the error and possibly exit } else if(msg.message==WM_TIMER) { count++; printf("WM_TIMER in work thread count=%d\n",count); if(count>4) break; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } KillTimer(NULL,timerid); printf("thread end here\n"); return 0;} vc++做串口通信绘制曲线 DLL函数返回值的问题 着急的问:帮忙看看我的程序错误出在什么地方,谢谢! 积!!!一个位图菜单的问题? $$$$$$$$$$$$$$$$$共享资源$$$$$$$$$$$$$$$$ 使用ADO执行SQL语句后,怎么输出啊? 如何做SMTP服务器? *****求教一个小问题***** 我有一个debug 版本的程序,想把它做成release版本,怎么办呢? MCSE OR 高级程序员? 请问如何取得子网掩码? 求教客户端使用智能指针访问Com组件的问题
#include <stdio.h>
#include <conio.h>
unsigned long WINAPI Thread(PVOID pvoid);
void main()
{
DWORD dwThreadId;
printf("use timer in workthread of console application<masterz>\n");
HANDLE hThread = CreateThread(
NULL, // no security attributes
0, // use default stack size
Thread, // thread function
0, // argument to thread function
0, // use default creation flags
&dwThreadId);
DWORD dwwait=WaitForSingleObject(hThread,1000*30);
switch(dwwait)
{
case WAIT_ABANDONED:
printf("main thread WaitForSingleObject return WAIT_ABANDONED\n");
break;
case WAIT_OBJECT_0:
printf("main thread WaitForSingleObject return WAIT_OBJECT_0\n");
break;
case WAIT_TIMEOUT:
printf("main thread WaitForSingleObject return WAIT_TIMEOUT\n");
break;
}
CloseHandle(hThread);
_getch();
}unsigned long WINAPI Thread(PVOID pvoid)
{
MSG msg;
PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
UINT timerid=SetTimer(NULL,111,3000,NULL);
BOOL bRet;
int count =0;
while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
}
else
if(msg.message==WM_TIMER)
{
count++;
printf("WM_TIMER in work thread count=%d\n",count);
if(count>4)
break;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
KillTimer(NULL,timerid);
printf("thread end here\n");
return 0;
}