Window线程的消息队列长度是多少?有没有溢出的可能呢?

xuexw 2002-10-11 05:38:09
Window线程的消息队列长度是多少?有没有溢出的可能呢?
...全文
584 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
temp77 2002-10-12
  • 打赏
  • 举报
回复
为了验证楼上人兄说的,特意编写程序如下


// File Name: WinMain.cpp

#define WIN32_LEAN_AND_MEAN // Say No to MFC !!

#include <windows.h>



char Temp[77]="Hello world";




// Name: WinMain()
// ------ ---------- ----------- ---------
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{


MessageBox( NULL, "按确定开始测试", "Simple_Code __CopyRight - `海风 ", MB_OK | MB_TOPMOST );

DWORD CurThreadID = GetCurrentThreadId( );

long i = 1 ;
for ( i = 1; i < 900000; i++)
{
if (! PostThreadMessage( CurThreadID, WM_USER , 11, 22 ) ) break;
// 上面的一句是如果不能再添加消息就打断 for 循环
}

wsprintf (Temp, "具体的消息队列长度是 %ld ", i);

MessageBox( NULL, Temp, "Sample_Code __CopyRight - `海风 ", MB_OK | MB_TOPMOST );

ExitProcess(0);
return NULL;
}




在 win2000 中运行的结果是 :10000 没错!


超出的当然是不能够再写入消息队列了,自然而然的就会丢失了,要尽量避免这种情况。
Fishcat 2002-10-12
  • 打赏
  • 举报
回复
ok
athere_08 2002-10-12
  • 打赏
  • 举报
回复
长度在一个注册表的键中,msdn上说了。
Windows 2000/XP: There is a limit of 10,000 posted messages per message queue. This limit should be sufficiently large. If your application exceeds the limit, it should be redesigned to avoid consuming so many system resources. To adjust this limit, modify the following registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\USERPostMessageLimit.

The minimum acceptable value is 4000.

bladeboy 2002-10-12
  • 打赏
  • 举报
回复
消息一般会被及时处理掉
xuexw 2002-10-12
  • 打赏
  • 举报
回复
溢出后有什么异常吗
ancienttale 2002-10-12
  • 打赏
  • 举报
回复
10000
ancienttale 2002-10-12
  • 打赏
  • 举报
回复
1000

siphonelee 2002-10-12
  • 打赏
  • 举报
回复
超出部分消息会丢失
导致系统工作异常
qrlvls 2002-10-12
  • 打赏
  • 举报
回复
不会,要不然……

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧