⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csdn_文档中心_线程通信初探.htm

📁 csdn10年中间经典帖子
💻 HTM
📖 第 1 页 / 共 3 页
字号:
            &nbsp;::WaitForSingleObject(m_start,INFINITE);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp;while(nCount&lt;500)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp;&nbsp;Add(nCount);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp;&nbsp;if(::WaitForSingleObject(m_start,0)=WAIT_OBJECT_0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp;::PostMessage(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp; 
            (HWND)pParam,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp; 
            WM_THREADFINISHED,//用户自定义消息<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp; 
            0,0);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp; return 
            0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            其中第一个WaitForSingleObject的调用等待启动事件,INFINITE使其等待直到启动事件有信号。第二个调用若有信号,立即返回,中止线程。<BR></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<TABLE align=center bgColor=#006699 border=0 cellPadding=0 cellSpacing=0 
width=770>
  <TBODY>
  <TR bgColor=#006699>
    <TD align=middle bgColor=#006699 id=white><FONT 
    color=#ffffff>对该文的评论</FONT></TD>
    <TD align=middle>
      <SCRIPT src="CSDN_文档中心_线程通信初探.files/readnum.htm"></SCRIPT>
    </TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1 
width=770>
  <TBODY>
  <TR>
    <TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16 
      hspace=1 src="CSDN_文档中心_线程通信初探.files/ico_pencil.gif" width=16> 
      </SPAN>&nbsp;&nbsp;&nbsp;&nbsp; yanw0212 <I>(2004-2-28 9:33:31)</I> </TD></TR>
  <TR>
    <TD bgColor=#ffffff colSpan=3 
      width=532><BR>我对楼主关于“主线程和辅助线程间的通信方式有很多种,这里利用消息通信是行不通的,因为辅助线程没有消息循环,不能够利用 
      Windows消息。”有些不同的看法:在主线程中也可以用消息的方式与辅助线程通讯,在主线程中: PostThreadMessage( 
      ThreadID, WM_SENDCMGS, 0, 0 ); 在辅助线程中: while ( true ) { 
      /*-------------------------------------------*/ MSG Msg; DWORD dwResult; 
      // do not wait in the first time this thread executes 
      dwResult=::MsgWaitForMultipleObjects( 0, 0, false, 5000, QS_POSTMESSAGE ); 
      if (dwResult == WAIT_OBJECT_0) {// // 
      --------------------------------------------------------------- // A 
      message has arrived to this thread // 
      --------------------------------------------------------------- 
      if(PeekMessage( &amp;Msg, // address of structure with message NULL, // 
      retrieve messages posted to this thread 0, 0, // do not perform any 
      message filtering PM_REMOVE /*| PM_QS_POSTMESSAGE */) ) // message is 
      removed from the queue { if ( Msg.message==WM_SENDCMGS ) // 接收正常,顺序:1 { 
      MessageBox(NULL,"接受 Msg.message == WM_SENDCMGS","",MB_OK | 0x00040000L ); 
      //OnSendCMGS(Msg.wParam, Msg.lParam); continue; } } } 
<BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1 
width=770>
  <TBODY>
  <TR>
    <TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16 
      hspace=1 src="CSDN_文档中心_线程通信初探.files/ico_pencil.gif" width=16> 
      </SPAN>&nbsp;&nbsp;&nbsp;&nbsp; wugng <I>(2001-12-8 12:39:36)</I> </TD></TR>
  <TR>
    <TD bgColor=#ffffff colSpan=3 width=532><BR>不错,不错,可是我看你的例子怎么那么眼熟, 怎么和VC++ 
      内幕上的一个样呀? <BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1 
width=770>
  <TBODY>
  <TR>
    <TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16 
      hspace=1 src="CSDN_文档中心_线程通信初探.files/ico_pencil.gif" width=16> 
      </SPAN>&nbsp;&nbsp;&nbsp;&nbsp; RealaKang <I>(2001-9-4 11:56:26)</I> 
</TD></TR>
  <TR>
    <TD bgColor=#ffffff colSpan=3 
      width=532><BR>我在做一个数据采集的程序,需要一个辅助工作线程来将采集的数据存入数据库(主线程采集数据是不间断采集的,而辅助线程是每1秒入库一次),我以前没编过多线程的程序。我想请教你如何挂起辅助线程。或者你觉的我是该每秒AfxBeginThread一个新的入库线程,写入一次数据就终止线程。我觉的还是写一次以后挂起,等一秒以后唤醒更好,可是不知如何挂起和唤醒。是不是问的太烦了,哎,没法啊,谁让我菜呢! 
      <BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1 
width=770>
  <TBODY>
  <TR>
    <TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16 
      hspace=1 src="CSDN_文档中心_线程通信初探.files/ico_pencil.gif" width=16> 
      </SPAN>&nbsp;&nbsp;&nbsp;&nbsp; chifire <I>(2001-1-8 13:53:56)</I> </TD></TR>
  <TR>
    <TD bgColor=#ffffff colSpan=3 width=532><BR>文章写的不错!继续努力!回应少说明都看明白了,没必要再问了。 
      <BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1 
width=770>
  <TBODY>
  <TR>
    <TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16 
      hspace=1 src="CSDN_文档中心_线程通信初探.files/ico_pencil.gif" width=16> 
      </SPAN>&nbsp;&nbsp;&nbsp;&nbsp; panda_w <I>(2001-1-7 10:25:39)</I> </TD></TR>
  <TR>
    <TD bgColor=#ffffff colSpan=3 width=532><BR>谢谢,不懂说明我的文章不好,下次一定用我十二分的努力写!! 
      <BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1 
width=770>
  <TBODY>
  <TR>
    <TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16 
      hspace=1 src="CSDN_文档中心_线程通信初探.files/ico_pencil.gif" width=16> 
      </SPAN>&nbsp;&nbsp;&nbsp;&nbsp; bzshow <I>(2001-1-6 15:50:58)</I> </TD></TR>
  <TR>
    <TD bgColor=#ffffff colSpan=3 width=532><BR>看不懂 <BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1 
width=770>
  <TBODY>
  <TR>
    <TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16 
      hspace=1 src="CSDN_文档中心_线程通信初探.files/ico_pencil.gif" width=16> 
      </SPAN>&nbsp;&nbsp;&nbsp;&nbsp; panda_w <I>(2000-12-30 9:36:11)</I> </TD></TR>
  <TR>
    <TD bgColor=#ffffff colSpan=3 width=532><BR>真的对不住大家了,怎么贴上去后的大小写全变成小写了呢? 
      <BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1 
width=770>
  <TBODY>
  <TR>
    <TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16 
      hspace=1 src="CSDN_文档中心_线程通信初探.files/ico_pencil.gif" width=16> 
      </SPAN>&nbsp;&nbsp;&nbsp;&nbsp; panda_w <I>(2000-12-29 13:35:42)</I> 
</TD></TR>
  <TR>
    <TD bgColor=#ffffff colSpan=3 
      width=532><BR>怎么大家看了没有人回应呢,就是差到不能回应的地步也求大家说句话啊! 
<BR></TD></TR></TBODY></TABLE><BR>
<DIV align=center>
<TABLE align=center bgColor=#cccccc border=0 cellPadding=2 cellSpacing=1 
width=770>
  <TBODY>
  <TR>
    <TH bgColor=#006699 id=white><FONT 
color=#ffffff>我要评论</FONT></TH></TR></TBODY></TABLE></DIV>
<DIV align=center>
<TABLE border=0 width=770>
  <TBODY>
  <TR>
    <TD>你没有登陆,无法发表评论。 请先<A 
      href="http://www.csdn.net/member/login.asp?from=/Develop/read_article.asp?id=2717">登陆</A> 
      <A 
href="http://www.csdn.net/expert/zc.asp">我要注册</A><BR></TD></TR></TBODY></TABLE></DIV><BR>
<HR noShade SIZE=1 width=770>

<TABLE border=0 cellPadding=0 cellSpacing=0 width=500>
  <TBODY>
  <TR align=middle>
    <TD height=10 vAlign=bottom><A 
      href="http://www.csdn.net/intro/intro.asp?id=2">网站简介</A> - <A 
      href="http://www.csdn.net/intro/intro.asp?id=5">广告服务</A> - <A 
      href="http://www.csdn.net/map/map.shtm">网站地图</A> - <A 
      href="http://www.csdn.net/help/help.asp">帮助信息</A> - <A 
      href="http://www.csdn.net/intro/intro.asp?id=2">联系方式</A> - <A 
      href="http://www.csdn.net/english">English</A> </TD>
    <TD align=middle rowSpan=3><A 
      href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010"><IMG 
      border=0 height=48 src="CSDN_文档中心_线程通信初探.files/biaoshi.gif" 
    width=40></A></TD></TR>
  <TR align=middle>
    <TD vAlign=top>百联美达美公司 版权所有 京ICP证020026号</TD></TR>
  <TR align=middle>
    <TD vAlign=top><FONT face=Verdana>Copyright &copy; CSDN.net, Inc. All rights 
      reserved</FONT></TD></TR>
  <TR>
    <TD height=15></TD>
    <TD></TD></TR></TBODY></TABLE></DIV>
<DIV></DIV><!--内容结束//--><!--结束//--></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -