I have a c++ code where I create a thread when I push a button. When I push twice I have multithreading and I experiment how a thread waits for another by WaitForSingleObject() which apply on an Event object.
If I define the Event object as static, CreateEvent() in the constructor method, and OpenEvent at the begining of the function that implements the thread, all seems to be OK.
But if I define the Event object elsewhere, nonstatic, seems that the OpenEvent at the begining of the function that implements the thread doesn’t work properly and the thread doesn’t wait one for another,although the OpenEvent returns non null.
HANDLE hevent0;
hevent0=CreateEvent(NULL,TRUE,TRUE,_T("hevenim"));
…
HANDLE hevent;
hevent=OpenEvent(EVENT_ALL_ACCESS,TRUE, _T("hevenim"));
rwait=WaitForSingleObject(hevent,9999);
My question is why the OpenEvent doesn’t work properly in the second case?