.NET wrapping a call/callback pair to appear synchronous -
I have a third party COM object that uses event callback to make the call to indicate that Has finished my work.
obj.Start ();
Then after some time, it will raise an incident to say that it is done.
P>
obj.Start () has tried to use auto reset events to handle; M_autoReset.WaitOne ();
and in the event handler:
zero operationfinished () {m_autoReset.Set (); }
But it seems that the set () and waiton () are both on the same thread, so it gets trapped. Is this an easy way to handle?
There is a quick thought over the top of my head, but it does not appear to be why it is not Does
Private Readonly Object m_locker = new object (); Private volatile bull m_complete;
.
lock (m_locker) {m_complete = false; } Obj.start (); While (true) {bull full lock (m_locker) {full = m_complete; } If (complete) {break; } Thread Sleep (500); // Wait for half-a-second, to see what we have done. YMMV }
.
zero operationfinished () {lock (m_locker) {m_complete = true; }}
Comments
Post a Comment