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

📄 waitforsingleobject_problem.mht

📁 WaitForSingleObject和WaitForMultipleObjects使用详解
💻 MHT
📖 第 1 页 / 共 5 页
字号:
href=3D"http://blog.csdn.net/egxsun/archive/2006/09/25/1274601.aspx">=E4=B8=
=8A=E4=B8=80=E7=AF=87: =E5=9C=A8SDK=E7=A8=8B=E5=BA=8F=E4=B8=AD=E4=BD=
=BF=E7=94=A8MFC=E4=B8=AD=E7=9A=84=E8=BE=85=E5=8A=A9=E7=B1=BB=E5=BA=93</A>=
&nbsp;|&nbsp;<A=20
href=3D"http://blog.csdn.net/egxsun/archive/2006/09/09/1199686.aspx">=E4=B8=
=8B=E4=B8=80=E7=AF=87:&nbsp;linux=E4=B8=8B=E7=94=A8=E6=9D=A5=E4=BF=AE=E6=94=
=B9=E7=B3=BB=E7=BB=9F=E6=97=B6=E9=97=B4=E7=9A=84=E5=87=BD=E6=95=B0=20
</A></DIV></SPAN><BR>
<SCRIPT>function =
StorePage(){d=3Ddocument;t=3Dd.selection?(d.selection.type!=3D'None'?d.se=
lection.createRange().text:''):(d.getSelection?d.getSelection():'');void(=
keyit=3Dwindow.open('http://www.365key.com/storeit.aspx?t=3D'+escape(d.ti=
tle)+'&u=3D'+escape(d.location.href)+'&c=3D'+escape(t),'keyit','scrollbar=
s=3Dno,width=3D475,height=3D575,left=3D75,top=3D20,status=3Dno,resizable=3D=
yes'));keyit.focus();}</SCRIPT>

<DIV class=3Dpost>
<DIV class=3DpostTitle><A=20
href=3D"http://blog.csdn.net/egxsun/articles/1210398.aspx"><IMG =
height=3D13=20
src=3D"http://blog.csdn.net/images/zhuan.gif" width=3D15=20
border=3D0>&nbsp;WaitForSingleObject=E5=92=8CWaitForMultipleObjects=E4=BD=
=BF=E7=94=A8=E8=AF=A6=E8=A7=A3</A> </DIV>
<DIV class=3DpostText>
<P><BR>WaitForSingleObject=E7=9A=84=E7=94=A8=E6=B3=95</P>
<P>DWORD WaitForSingleObject(<BR>&nbsp; HANDLE hHandle,<BR>&nbsp; DWORD=20
dwMilliseconds<BR>);<BR>=E5=8F=82=E6=95=B0hHandle=E6=98=AF=E4=B8=80=E4=B8=
=AA=E4=BA=8B=E4=BB=B6=E7=9A=84=E5=8F=A5=E6=9F=84=EF=BC=8C=E7=AC=AC=E4=BA=8C=
=E4=B8=AA=E5=8F=82=E6=95=B0dwMilliseconds=E6=98=AF=E6=97=B6=E9=97=B4=E9=97=
=B4=E9=9A=94=E3=80=82=E5=A6=82=E6=9E=9C=E6=97=B6=E9=97=B4=E6=98=AF=E6=9C=89=
=E4=BF=A1=E5=8F=B7=E7=8A=B6=E6=80=81=E8=BF=94=E5=9B=9EWAIT_OBJECT_0=EF=BC=
=8C=E5=A6=82=E6=9E=9C=E6=97=B6=E9=97=B4=E8=B6=85=E8=BF=87dwMilliseconds=E5=
=80=BC=E4=BD=86=E6=97=B6=E9=97=B4=E4=BA=8B=E4=BB=B6=E8=BF=98=E6=98=AF=E6=97=
=A0=E4=BF=A1=E5=8F=B7=E7=8A=B6=E6=80=81=E5=88=99=E8=BF=94=E5=9B=9EWAIT_TI=
MEOUT=E3=80=82</P>
<P>hHandle=E5=8F=AF=E4=BB=A5=E6=98=AF=E4=B8=8B=E5=88=97=E5=AF=B9=E8=B1=A1=
=E7=9A=84=E5=8F=A5=E6=9F=84=EF=BC=9A</P>
<P>&nbsp;&nbsp;&nbsp; Change notification <BR>Console input <BR>Event =
<BR>Job=20
<BR>Memory resource notification <BR>Mutex <BR>Process <BR>Semaphore =
<BR>Thread=20
<BR>Waitable timer </P>
<P><BR>WaitForSingleObject=E5=87=BD=E6=95=B0=E7=94=A8=E6=9D=A5=E6=A3=80=E6=
=B5=8BhHandle=E4=BA=8B=E4=BB=B6=E7=9A=84=E4=BF=A1=E5=8F=B7=E7=8A=B6=E6=80=
=81=EF=BC=8C=E5=BD=93=E5=87=BD=E6=95=B0=E7=9A=84=E6=89=A7=E8=A1=8C=E6=97=B6=
=E9=97=B4=E8=B6=85=E8=BF=87dwMilliseconds=E5=B0=B1=E8=BF=94=E5=9B=9E=EF=BC=
=8C=E4=BD=86=E5=A6=82=E6=9E=9C=E5=8F=82=E6=95=B0dwMilliseconds=E4=B8=BAIN=
FINITE=E6=97=B6=E5=87=BD=E6=95=B0=E5=B0=86=E7=9B=B4=E5=88=B0=E7=9B=B8=E5=BA=
=94=E6=97=B6=E9=97=B4=E4=BA=8B=E4=BB=B6=E5=8F=98=E6=88=90=E6=9C=89=E4=BF=A1=
=E5=8F=B7=E7=8A=B6=E6=80=81=E6=89=8D=E8=BF=94=E5=9B=9E=EF=BC=8C=E5=90=A6=E5=
=88=99=E5=B0=B1=E4=B8=80=E7=9B=B4=E7=AD=89=E5=BE=85=E4=B8=8B=E5=8E=BB=EF=BC=
=8C=E7=9B=B4=E5=88=B0WaitForSingleObject=E6=9C=89=E8=BF=94=E5=9B=9E=E7=9B=
=B4=E6=89=8D=E6=89=A7=E8=A1=8C=E5=90=8E=E9=9D=A2=E7=9A=84=E4=BB=A3=E7=A0=81=
=E3=80=82=E5=9C=A8=E8=BF=99=E9=87=8C=E4=B8=BE=E4=B8=AA=E4=BE=8B=E5=AD=90=EF=
=BC=9A</P>
<P>=E5=85=88=E5=88=9B=E5=BB=BA=E4=B8=80=E4=B8=AA=E5=85=A8=E5=B1=80Event=E5=
=AF=B9=E8=B1=A1g_event:</P>
<P>&nbsp;&nbsp;&nbsp; CEvent g_event;</P>
<P>=E5=9C=A8=E7=A8=8B=E5=BA=8F=E4=B8=AD=E5=8F=AF=E4=BB=A5=E9=80=9A=E8=BF=87=
=E8=B0=83=E7=94=A8CEvent::SetEvent=E8=AE=BE=E7=BD=AE=E4=BA=8B=E4=BB=B6=E4=
=B8=BA=E6=9C=89=E4=BF=A1=E5=8F=B7=E7=8A=B6=E6=80=81=E3=80=82</P>
<P>=E4=B8=8B=E9=9D=A2=E6=98=AF=E4=B8=80=E4=B8=AA=E7=BA=BF=E7=A8=8B=E5=87=BD=
=E6=95=B0MyThreadPro()</P>
<P>UINT CFlushDlg::MyThreadProc( LPVOID pParam ) </P>
<P><BR>{ </P>
<P><BR>&nbsp;&nbsp;&nbsp;&nbsp; WaitForSingleObject(g_event,INFINITE); =
</P>
<P><BR>&nbsp;&nbsp;&nbsp;&nbsp; For(;;) </P>
<P><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { </P>
<P><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
=E2=80=A6=E2=80=A6=E2=80=A6=E2=80=A6. </P>
<P><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } </P>
<P><BR>&nbsp;&nbsp;&nbsp;&nbsp; return 0; </P>
<P><BR>} </P>
<P><BR>=E5=9C=A8=E8=BF=99=E4=B8=AA=E7=BA=BF=E7=A8=8B=E5=87=BD=E6=95=B0=E4=
=B8=AD=E5=8F=AA=E6=9C=89=E8=AE=BE=E7=BD=AEg_event=E4=B8=BA=E6=9C=89=E4=BF=
=A1=E5=8F=B7=E7=8A=B6=E6=80=81=E6=97=B6=E6=89=8D=E6=89=A7=E8=A1=8C=E4=B8=8B=
=E9=9D=A2=E7=9A=84for=E5=BE=AA=E7=8E=AF=EF=BC=8C=E5=9B=A0=E4=B8=BAg_event=
=E6=98=AF=E5=85=A8=E5=B1=80=E5=8F=98=E9=87=8F=EF=BC=8C=E6=89=80=E4=BB=A5=E6=
=88=91=E4=BB=AC=E5=8F=AF=E4=BB=A5=E5=9C=A8=E5=88=AB=E7=9A=84=E7=BA=BF=E7=A8=
=8B=E4=B8=AD=E9=80=9A=E8=BF=87g_event.=20
SetEvent=E6=8E=A7=E5=88=B6=E8=BF=99=E4=B8=AA=E7=BA=BF=E7=A8=8B=E3=80=82</=
P>
<P><BR>&nbsp;</P>
<P><BR>=E8=BF=98=E6=9C=89=E4=B8=80=E7=A7=8D=E7=94=A8=E6=B3=95=E5=B0=B1=E6=
=98=AF=E6=88=91=E4=BB=AC=E5=8F=AF=E4=BB=A5=E9=80=9A=E8=BF=87WaitForSingle=
Object=E5=87=BD=E6=95=B0=E6=9D=A5=E9=97=B4=E9=9A=94=E7=9A=84=E6=89=A7=E8=A1=
=8C=E4=B8=80=E4=B8=AA=E7=BA=BF=E7=A8=8B=E5=87=BD=E6=95=B0=E7=9A=84=E5=87=BD=
=E6=95=B0=E4=BD=93</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; UINT CFlushDlg::MyThreadProc( LPVOID pParam =
) </P>
<P><BR>{ </P>
<P><BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
while(WaitForSingleObject(g_event,MT_INTERVAL)!=3DWAIT_OBJECT_0) </P>
<P><BR>&nbsp;&nbsp;&nbsp;&nbsp; { </P>
<P><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
=E2=80=A6=E2=80=A6=E2=80=A6=E2=80=A6=E2=80=A6=E2=80=A6 </P>
<P><BR>&nbsp;&nbsp;&nbsp;&nbsp; } </P>
<P><BR>&nbsp;&nbsp;&nbsp;&nbsp; return 0; </P>
<P><BR>} </P>
<P><BR>=E5=9C=A8=E8=BF=99=E4=B8=AA=E7=BA=BF=E7=A8=8B=E5=87=BD=E6=95=B0=E4=
=B8=AD=E5=8F=AF=E4=BB=A5=E5=8F=AF=E4=BB=A5=E9=80=9A=E8=BF=87=E8=AE=BE=E7=BD=
=AEMT_INTERVAL=E6=9D=A5=E6=8E=A7=E5=88=B6=E8=BF=99=E4=B8=AA=E7=BA=BF=E7=A8=
=8B=E7=9A=84=E5=87=BD=E6=95=B0=E4=BD=93=E5=A4=9A=E4=B9=85=E6=89=A7=E8=A1=8C=
=E4=B8=80=E6=AC=A1=EF=BC=8C=E5=BD=93=E4=BA=8B=E4=BB=B6=E4=B8=BA=E6=97=A0=E4=
=BF=A1=E5=8F=B7=E7=8A=B6=E6=80=81=E6=98=AF=E5=87=BD=E6=95=B0=E4=BD=93=E9=9A=
=94MT_INTERVAL=E6=89=A7=E8=A1=8C=E4=B8=80=E6=AC=A1=EF=BC=8C=E5=BD=93=E8=AE=
=BE=E7=BD=AE=E4=BA=8B=E4=BB=B6=E4=B8=BA=E6=9C=89=E4=BF=A1=E5=8F=B7=E7=8A=B6=
=E6=80=81=E6=97=B6=EF=BC=8C=E7=BA=BF=E7=A8=8B=E5=B0=B1=E6=89=A7=E8=A1=8C=E5=
=AE=8C=E6=AF=95=E4=BA=86=E3=80=82</P>
<P>&nbsp;</P>
<P>&nbsp;</P>
<P>WaitForMultipleObjects<BR>&nbsp;</P>
<P>The WaitForMultipleObjects function returns when one of the following =
occurs:=20
</P>
<P>&nbsp;</P>
<P><BR>Either any one or all of the specified objects are in the =
signaled state.=20
</P>
<P>The time-out interval elapses. </P>
<P>&nbsp;</P>
<P>To enter an alertable wait state, use the WaitForMultipleObjectsEx =
function.=20
</P>
<P>DWORD WaitForMultipleObjects(<BR>&nbsp; DWORD=20
nCount,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;=20
// number of handles in array<BR>&nbsp; CONST HANDLE *lpHandles,&nbsp; =
//=20
object-handle array<BR>&nbsp; BOOL=20
bWaitAll,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; //=20
wait option<BR>&nbsp; DWORD dwMilliseconds&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
//=20
time-out interval<BR>);</P>
<P>&nbsp;</P>
<P><BR>&nbsp;</P>
<P>Parameters</P>
<P>&nbsp;</P>
<P>&nbsp;</P>
<P>nCount </P>
<P>[in] Specifies the number of object handles in the array pointed to =
by=20
lpHandles. The maximum number of object handles is MAXIMUM_WAIT_OBJECTS. =
</P>
<P>lpHandles </P>
<P>[in] Pointer to an array of object handles. For a list of the object =
types=20
whose handles can be specified, see the following Remarks section. The =
array can=20
contain handles to objects of different types. It may not contain the =
multiple=20
copies of the same handle. </P>
<P>If one of these handles is closed while the wait is still pending, =
the=20
function's behavior is undefined. </P>
<P><BR>Windows NT/2000/XP: The handles must have SYNCHRONIZE access. For =
more=20
information, see Standard Access Rights. </P>
<P><BR>Windows 95/98/Me: No handle may be a duplicate of another handle =
created=20
using DuplicateHandle. </P>
<P>&nbsp;</P>
<P>bWaitAll </P>
<P>[in] Specifies the wait type. If TRUE, the function returns when the =
state of=20
all objects in the lpHandles array is signaled. If FALSE, the function =
returns=20
when the state of any one of the objects is set to signaled. In the =
latter case,=20
the return value indicates the object whose state caused the function to =
return.=20
</P>
<P>dwMilliseconds </P>
<P>[in] Specifies the time-out interval, in milliseconds. The function =
returns=20
if the interval elapses, even if the conditions specified by the =
bWaitAll=20
parameter are not met. If dwMilliseconds is zero, the function tests the =
states=20
of the specified objects and returns immediately. If dwMilliseconds is =
INFINITE,=20
the function's time-out interval never elapses. </P>
<P>&nbsp;</P>
<P>Return Values</P>
<P>&nbsp;</P>
<P>If the function succeeds, the return value indicates the event that =
caused=20
the function to return. This value can be one of the following.=20
<BR>&nbsp;<BR>&nbsp;</P><BR><BR>
<P id=3DTBPingURL>Trackback:=20
http://tb.blog.csdn.net/TrackBack.aspx?PostId=3D1210398</P><BR></DIV>
<DIV class=3DpostFoot>
<SCRIPT src=3D""></SCRIPT>
[<A =
title=3D=E5=8A=9F=E8=83=BD=E5=BC=BA=E5=A4=A7=E7=9A=84=E7=BD=91=E7=BB=9C=E6=
=94=B6=E8=97=8F=E5=A4=B9=EF=BC=8C=E4=B8=80=E7=A7=92=E9=92=9F=E6=93=8D=E4=BD=
=9C=E5=B0=B1=E5=8F=AF=E4=BB=A5=E8=BD=BB=E6=9D=BE=E5=AE=9E=E7=8E=B0=E4=BF=9D=
=E5=AD=98=E5=B8=A6=E6=9D=A5=E7=9A=84=E4=BB=B7=E5=80=BC=E3=80=81=E5=88=86=E4=
=BA=AB=E5=B8=A6=E6=9D=A5=E7=9A=84=E5=BF=AB=E4=B9=90=20
href=3D"javascript:d=3Ddocument;t=3Dd.selection?(d.selection.type!=3D'Non=
e'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():''=
);void(saveit=3Dwindow.open('http://wz.csdn.net/storeit.aspx?t=3D'+escape=
(d.title)+'&amp;u=3D'+escape(d.location.href)+'&amp;c=3D'+escape(t),'keyi=
t','scrollbars=3Dno,width=3D590,height=3D300,left=3D75,top=3D20,status=3D=
no,resizable=3Dyes'));saveit.focus();">=E6=94=B6=E8=97=8F=E5=88=B0=E6=88=91=
=E7=9A=84=E7=BD=91=E6=91=98</A>]&nbsp;&nbsp;=20
egxsun=E5=8F=91=E8=A1=A8=E4=BA=8E 2006=E5=B9=B409=E6=9C=8811=E6=97=A5 =
23:00:00 </DIV></DIV><LINK=20
href=3D"http://blog.csdn.net/egxsun/Services/Pingback.aspx" =
rel=3Dpingback><!--<rdf:RDF =
xmlns:rdf=3D"http://www.w3.org/1999/02/22-rdf-syntax-ns#"xmlns:dc=3D"http=
://purl.org/dc/elements/1.1/"xmlns:trackback=3D"http://madskills.com/publ=
ic/xml/rss/module/trackback/"><rdf:Descriptionrdf:about=3D"http://blog.cs=
dn.net/egxsun/articles/1210398.aspx"dc:identifier=3D"http://blog.csdn.net=
/egxsun/articles/1210398.aspx"dc:title=3D"WaitForSingleObject=E5=92=8CWai=
tForMultipleObjects=E4=BD=BF=E7=94=A8=E8=AF=A6=E8=A7=A3"trackback:ping=3D=
"http://tb.blog.csdn.net/TrackBack.aspx?PostId=3D1210398" =
/></rdf:RDF>-->
<SCRIPT>function hide(){showComment();}</SCRIPT>
<BR><BR><BR><BR>
<DIV class=3Dpost id=3Dcsdn_zhaig_ad_yahoo></DIV>
<SCRIPT type=3Dtext/javascript>document.write("<img =
src=3Dhttp://counter.csdn.net/pv.aspx?id=3D24 border=3D0 width=3D0 =
height=3D0>");</SCRIPT>
<SPAN class=3DPreAndNext id=3Dviewpost.ascx_PreviousAndNextEntriesDown>
<DIV align=3Dcenter><A=20
href=3D"http://blog.csdn.net/egxsun/archive/2006/09/25/1274601.aspx">=E4=B8=
=8A=E4=B8=80=E7=AF=87:&nbsp;=E5=9C=A8SDK=E7=A8=8B=E5=BA=8F=E4=B8=AD=E4=BD=
=BF=E7=94=A8MFC=E4=B8=AD=E7=9A=84=E8=BE=85=E5=8A=A9=E7=B1=BB=E5=BA=93</A>=
&nbsp;|&nbsp;<A=20
href=3D"http://blog.csdn.net/egxsun/archive/2006/09/09/1199686.aspx">=E4=B8=
=8B=E4=B8=80=E7=AF=87:&nbsp;linux=E4=B8=8B=E7=94=A8=E6=9D=A5=E4=BF=AE=E6=94=
=B9=E7=B3=BB=E7=BB=9F=E6=97=B6=E9=97=B4=E7=9A=84=E5=87=BD=E6=95=B0=20
</A></DIV></SPAN><SPAN id=3DAnthem_Comments.ascx_ltlComments__><SPAN=20
id=3DComments.ascx_ltlComments><BR>
<DIV id=3Dcomments>
<H3></H3>=E6=B2=A1=E6=9C=89=E8=AF=84=E8=AE=BA=E3=80=82 =
</DIV></SPAN></SPAN>
<SCRIPT language=3Djavascript>
ad_width=3D468;
ad_height=3D60;
adcss=3D2;
unionuser=3D19;
ad_type=3D'j';
count=3D5;=20
</SCRIPT>

<DIV>
<SCRIPT language=3Djavascript src=3D"http://tagegg.csdn.net/showads.js"=20
type=3Dtext/javascript></SCRIPT>

<SCRIPT language=3Djavascript src=3D"http://blog.csdn.net/js/showgm.js"=20
type=3Dtext/javascript></SCRIPT>
</DIV>
<DIV class=3DCommentForm id=3Dcommentform>
<H3>=E5=8F=91=E8=A1=A8=E8=AF=84=E8=AE=BA </H3>
<DIV id=3DAnthem_PostComment.ascx_CommentUpdatePanel__>
<DIV id=3DPostComment.ascx_CommentUpdatePanel>
<TABLE class=3DCommentForm>
  <TBODY>
  <TR>
    <TD width=3D69 height=3D0></TD>
    <TD></TD></TR>
  <TR>
    <TD width=3D70>=E5=A4=A7=E5=90=8D=EF=BC=9A</TD>
    <TD align=3Dleft><INPUT id=3DPostComment.ascx_tbName style=3D"WIDTH: =
300px"=20
      disabled maxLength=3D32 size=3D40 name=3DPostComment.ascx:tbName> =
<SPAN=20
      id=3DPostComment.ascx_RequiredFieldValidator2=20
      style=3D"DISPLAY: none; COLOR: red" initialvalue=3D""=20
      evaluationfunction=3D"RequiredFieldValidatorEvaluateIsValid"=20
      display=3D"Dynamic" =
errormessage=3D"<br>=E8=AF=B7=E8=BE=93=E5=85=A5=E5=B0=8A=E5=A7=93=E5=A4=A7=
=E5=90=8D"=20
      =
controltovalidate=3D"PostComment.ascx_tbName"><BR>=E8=AF=B7=E8=BE=93=E5=85=
=A5=E5=B0=8A=E5=A7=93=E5=A4=A7=E5=90=8D</SPAN> </TD></TR>
  <TR>
    <TD width=3D70>=E7=BD=91=E5=9D=80=EF=BC=9A</TD>
    <TD align=3Dleft><INPUT id=3DPostComment.ascx_tbUrl style=3D"WIDTH: =
300px"=20
      disabled maxLength=3D256 size=3D40 name=3DPostComment.ascx:tbUrl> =
</TD></TR>
  <TR>
    <TD colSpan=3D3>=E8=AF=84=E8=AE=BA&nbsp; <SPAN =
id=3DPostComment.ascx_RequiredFieldValidator3=20
      style=3D"DISPLAY: none; COLOR: red" initialvalue=3D""=20
      evaluationfunction=3D"RequiredFieldValidatorEvaluateIsValid"=20
      display=3D"Dynamic" =
errormessage=3D"<br>=E8=AF=B7=E8=BE=93=E5=85=A5=E8=AF=84=E8=AE=BA"=20
      =
controltovalidate=3D"PostComment.ascx_tbComment"><BR>=E8=AF=B7=E8=BE=93=E5=

⌨️ 快捷键说明

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