// JP opened flex table

Click to See Complete Forum and Search --> : problem in using Mutex in com


sukanta
April 3rd, 2002, 06:26 AM
LISTSERV@DISCUSS.MICROSOFT.COM

Hi All

I would appreciate for any help with problem that listed below.

I have an in-proc component in which i have a method. I want that at a time only one process will excute that method. For this I have used a mutex. But it is not working. Two process excutes that method in the same time.

I have created a mutex in the constructor of the class and used that mutex in the method.
I have declared the mutex handle hmutex as protected type in the class.


CODE:

Cmutecom::Cmutecom()
{
hmutex = CreateMutex(NULL,FALSE,"sukamutex");
}
Cmutecom::~Cmutecom()
{
CloseHandle(hmutex);
}

STDMETHODIMP Cmutecom::Alertmsg1()
{
WaitForSingleObject(hmutex,INFINITE);
MessageBox(NULL,"alert1","alert1 mutex",MB_OK);
ReleaseMutex(hmutex);
return S_OK;
}

If any process is running in the method then other process should wait in the mothod for the first process to complete the mothod.
But it doesnot.

Any idea why it is happening so.

regards

Sukanta

//JP added flex table