901227-C#中需要WaitForSingleObject [英] 901227 - WaitForSingleObject is needed in C#
本文介绍了901227-C#中需要WaitForSingleObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在C ++中,这可以由WaitForSingleObject完成.
RegisterWaitForSingleObject
可能无济于事,因为它注册了单独的功能.我需要在相同的函数中等待,并且直到事件发生时才返回.我该怎么办?
thx
解决方案
从System.Threading.WaitHandle
派生的许多类中都可以使用此方法,请参见:
http://msdn.microsoft.com/en-us/library/system.threading. waithandle.aspx [ ^ ].
Paulo指出的两个当然很重要,但是除了使用它们之外,还可以使用其父类在功能上涵盖这两种情况(手动或自动重置).此类为System.Threading.EventWaitHandle
:
http://msdn.microsoft.com/en-us/library/system.threading. eventwaithandle.aspx [ ^ ].
—SA
请参见类AutoResetEvent和ManualResetEvent.
WaitForSingleObject实际上是WaitOne方法.
您也可以在我的文章中查找这些类的苗条"版本:托管线程同步 [ ^ ]
hi
in a function a wait must be done until a special variable reset or a special event is raised. how can i wait in the function?
in C++, this would be possible to be done by WaitForSingleObject. RegisterWaitForSingleObject
may not help, because it registers a separate function. i need to wait in the same function and don''t return until the event occurs.
what can i do?
thx
解决方案
This method is available in a number of classes derived fromSystem.Threading.WaitHandle
, please see:
http://msdn.microsoft.com/en-us/library/system.threading.waithandle.aspx[^].
The two pointed out by Paulo are of course very important, but instead of using them, one could use its parent class functionally covering both cases (manual or auto reset); this class isSystem.Threading.EventWaitHandle
:
http://msdn.microsoft.com/en-us/library/system.threading.eventwaithandle.aspx[^].
—SA
See the classes AutoResetEvent and ManualResetEvent.
The WaitForSingleObject is effectively the WaitOne method.
You can also look for "slim" version of those classes in my article: Managed Thread Synchronization[^]
这篇关于901227-C#中需要WaitForSingleObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文