Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-09-21
3
Medium Priority
?
220 Views
Last Modified: 2012-06-27
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.



0
Comment
Question by:joevm3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
jlsjls earned 2000 total points
ID: 12130922
I think the use of a Mutex could be a solution.
When you fire the event you try to get the ownership of the mutex (WaitForSingleObject(hMutex,INFINITE).
When OK, you fire the event to the application.
The application processes the event and after returning to the ocx you release the mutex.

At that moment, ocx2 can take the ownership of the mutex and can fire its data to the application. Again using procedure mentioned above.
Waiting for the mutex doesn't practically stress the CPU.

jlsjls
0
 

Author Comment

by:joevm3
ID: 12147231
how do you release the mutex?
what is hMutex... how do you initalize the mutex?

Thank you,
Joe
0
 
LVL 3

Expert Comment

by:jlsjls
ID: 12157998
* 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);
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question