Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 17-Mar-12 5:04am
v2

This method is available in a number of classes derived from System.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 is System.Threading.EventWaitHandle:
http://msdn.microsoft.com/en-us/library/system.threading.eventwaithandle.aspx[^].

—SA
 
Share this answer
 
Comments
(__Aaron__) 18-Mar-12 3:57am    
Good one.
Sergey Alexandrovich Kryukov 18-Mar-12 12:43pm    
Thank you, Aaron.
--SA
ilostmyid2 18-Mar-12 5:23am    
thank everyone who replied. :)
Sergey Alexandrovich Kryukov 18-Mar-12 12:44pm    
You are welcome.
Are you going to accept this answer formally (green button) -- thank you.
--SA
ilostmyid2 18-Mar-12 12:46pm    
sure :)
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[^]
 
Share this answer
 
Comments
ilostmyid2 17-Mar-12 11:46am    
thank u :)
Sergey Alexandrovich Kryukov 17-Mar-12 20:23pm    
Yes, but not exactly, so I voted 4.
There are other classes using WaitForSingleObject in Windows implementation of SLR, please see my answer.
--SA
Paulo Zemek 17-Mar-12 21:39pm    
I didn't said they were the only options... but I said to look at them both... depending on the situation they already solve the problem... or depending on the situation they are a good start (after all, I always see the inheritance of a class if that class is not exactly what I want).
Sergey Alexandrovich Kryukov 18-Mar-12 12:56pm    
I did not say you say something wrong...
I think that it's important to mention all of waiting classes, just because OP goes from WaitForSingleObject. In windows, API, this function also works with objects of several different types, that's why .NET implementation is based on a wrapper of a handle to the object to wait.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900