Solved

COM server sluggish during execution of client event sink

Posted on 2004-08-06
2
204 Views
Last Modified: 2010-04-24
I received some help from _ys_ on this, but as it turned out, as is often the case it only helped us narrow down the problem.  

We are writing a VC++ application that is started and monitors/commands hardware, collects/stores data and does some number-crunching.  We are also writing a VB HMI (an ActiveX EXE) that is created (when the user desires a UI) from the VC++ client using the CoCreateInstance command above.  So our VC++ engine is a COM client and our VB HMI is a COM Server.  They communicate through events and properties we've set up on the VB/HMI/Server side, and an event sink on the VC++/Engine/Client side.

With _ys_'s help, the VB server/HMI and C++ client/engine are perfectly independent, on separate threads: after CoCreateInstance I can run a modal dialog box and it locks up the engine but the HMI is free as a bird, which is perfect.

The problem starts when the user tries to start an "analysis" from the HMI.  We have written a 'TalkToEngine' event on the VB side (with some message parameters) and  implemented an event sink class in our C engine which traps the events (derived from IDispEventSimpleImpl).  The HMI can pass a message through this event which causes our event sink to call StartAnalysis.  StartAnalysis does a lot of number crunching and sends messages to the HMI.

When StartAnalysis is called from some other location in the VC++ engine, it works fine; the analysis starts and the HMI (if's been  instantiated) recevies and displays messages.  However, when StartAnalysis is called from the event sink (or from a method called from the event sink, et al.), then the HMI becomes very sluggish, it doesn't respond to mouse events, you occasionally get the "Switch to..." dialog box, until the analysis is complete.

I suppose this is because the call to StartAnalysis is not allowing the Event Sink to complete its processing.  Apparently the event sink must run its course and release something (what are the mechanics here?) to allow the two objects to operate independently again.  The problem is that I don't know how invoke the correct routines in the engine from the event sink *without* tying up the event sink until those routines are done (which is what appears to be tying up my HMI).

I actually tried rewriting the event sink to set a flag that is picked up by a timer outside of the event sink (inelegant and low-performance) and also starting a new thread to run StartAnalysis (but for some reason the new thread can't talk back to the VB/Server/HMI), but both were problematic.  There *has* to be a simpler way to do this.

Thanks very much.  High point value because I think this requires some narrow/deep expertise.  


0
Comment
Question by:riceman0
2 Comments
 

Author Comment

by:riceman0
ID: 11738250


"However, when StartAnalysis is called from the event sink (or from a method called from the event sink, et al.), then the HMI becomes very sluggish..."

In case this isn't clear, when the HMI starts the analysis it places a call to the engine event sink.  When we start the analysis this way it is slow.  When we start the analysis from within the engine it runs fine (including sending messages back to the HMI).

0
 
LVL 19

Accepted Solution

by:
drichards earned 250 total points
ID: 11797368
>>  I suppose this is because the call to StartAnalysis is not allowing the Event Sink to complete its processing.
>>  Apparently the event sink must run its course and release something (what are the mechanics here?) to
>>  allow the two objects to operate independently again.
Correct

>>  I actually tried rewriting the event sink to set a flag that is picked up by a timer outside of the event sink
>>  (inelegant and low-performance) and also starting a new thread to run StartAnalysis (but for some reason
>>  the new thread can't talk back to the VB/Server/HMI), but both were problematic.  There *has* to be a simpler way to do this.

Those are two options.  One potentially better variant would be to post a thread or windows message in the event sink - of course you must be handling messages to do this.  It would actively signal the C++ app to start the analysis and let the VB code return immediately as well.  This way you don't have to wait for a timer and you don't need a new thread.

If you do start a new thread to run the analysis, you will have to marshal into the new thread whatever COM interfaces you need to commuincate with the VB server.  You use 'CoMarshalInterThreadInterfaceInStream' and 'CoGetInterfaceAndReleaseStream' to do this.  In the event sink routine, you call 'CoMarshalInterThreadInterfaceInStream' on the desired interfaces and pass the IStream pointer to the new thread.  In the new thread you call 'CoGetInterfaceAndReleaseStream' to reconstiture the interface pointer.  Now you can do COM calls normally.

Check out the docs at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/cmf_a2c_88tp.asp

0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

773 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