Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey Friends

Has anybody used Named Events in Windows 7 ?

Struggling with Named Events, Works on XP , but not on Windows 7.

C#
SharedEvent = CreateEvent(NULL, FALSE, FALSE, "ProblemWithWin7Events");

    if (SharedEvent == NULL)
    {

        AfxMessageBox("Cannot create named event!");
    }

    AfxBeginThread(ThreadProc,this);



and in Thread Waiting for the Event to Signal

C#
DWORD       WaitStatus;

    for(int vl_iIndex = 1; vl_iIndex <=1000;vl_iIndex ++)
    {
        WaitStatus = WaitForSingleObject(SharedEvent, INFINITE);

        if (WaitStatus != WAIT_OBJECT_0)
        {
            TRACE("%d WaitForSingleObject Failed\n",vl_iIndex );
        }
        else
        {

            TRACE("%d WaitForSingleObject Works\n",vl_iIndex );
        }
    }


Also created a Button to Signal the Event

C#
void CTestApplicationForEventsDlg::OnBnClickedSignalEvent()
{
    HANDLE vl_hEvent = OpenEvent(SYNCHRONIZE ,FALSE,"ProblemWithWin7Events");

    if(vl_hEvent ==NULL)
    {
        AfxMessageBox("Could not Open Event");
        return;
    }
    ::SetEvent(vl_hEvent);
}


Any idea of what i am doing wrong ?

Regards
Posted
Comments
Albert Holguin 28-Nov-11 1:12am    
I'll look at your code closer closer tomorrow, but I use events all the time with no issue. What part failed? You never specify what the problem is.
CPallini 28-Nov-11 3:19am    
"I works on XP, it doesn't on Windows 7" is a very poor error description. Please elaborate.
SoftwareDeveloperGoa 28-Nov-11 5:05am    
On windows 7 WaitForSingleObject never comes out of waiting for the event even when the event is signalled.

Can you try using EVENT_ALL_ACCESS instead of SYNCHRONIZE as shown below??

C++
HANDLE vl_hEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE,"ProblemWithWin7Events");
 
Share this answer
 
yeah changing OpenEvent Parameter (Access Parameter , the First Parameter) solved the problem, thanks a lot all of you for helping me out here.

HANDLE vl_hEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE,"ProblemWithWin7Events");
 
Share this answer
 

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



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