Link to home
Start Free TrialLog in
Avatar of joevm3
joevm3Flag for United States of America

asked on

Events from OCX do not fire when the client app is busy with another event. [Events dropped]

If my OCX tries to fire an event but the client app is busy with another event, the event will be lost.
I am writing the OCX in VC++ 6, this OCX will be loaded multiple times in the client app.

Here is an example of my problem.

I have 2 instances of the OCX loaded on the client app.
OCX1 fires an event -> the client app receives the event and starts processing the code in the event.
If OCX2 fires an event while the client is still processing the previous event, this event will be lost.

Another example to help visualize the problem:

OCX1 fires an event
Client runs slow code in the event such as Sleep(1000)
OCX2 fires an event before the OCX1 event finishes
Client does not receive OCX2 event

My current solution that works but i cannot use because it uses ties up the CPU.
I have a global variable called HoldEvents [all instances of the OCX can read/set this variable]
my code to fire the event now looks as follows

while(HoldEvents) {}
HoldEvents=1;
FireBlahEvent(blah);
HoldEvents=0;

Does anyone know of a better solution? I don't like the idea of a loop and i cannot add sleep in the loop to use less CPU because the events are time critical and need to be fired as soon as the client app can take them.

Joe.



ASKER CERTIFIED SOLUTION
Avatar of jlsjls
jlsjls

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of joevm3

ASKER

how do you release the mutex?
what is hMutex... how do you initalize the mutex?

Thank you,
Joe
Avatar of jlsjls
jlsjls

* Creation of mutex (obtain handle hMutex to it) :
BOOL MakeMutex()
{
hMutex = CreateMutex(NULL,FALSE,TEXT("MyMutex"));
if (hMutex == NULL)
{
 return FALSE;
}
else
{
if (ERROR_ALREADY_EXISTS == GetLastError())
//mutex already created by other process or other thread
{
//MessageBox (NULL, TEXT("CreateMutex opened existing mutex."),TEXT("Results"), MB_OK);
}
else //new mutex was created
{                   
//MessageBox (NULL, TEXT("CreateMutex created new mutex."),TEXT("Results"), MB_OK);
}
}
return TRUE;
}

* Release the mutex
ReleaseMutex(hMutex);