Link to home
Start Free TrialLog in
Avatar of Metacrawler
MetacrawlerFlag for Germany

asked on

How to abort a call to a COM method?

Hello Community,

I'm trying to stabilize a COM server that provides events via connection points. When I call IDispatch::Invoke() to trigger an event sink method on the client, I don't know how long the client needs to finish running this method - perhaps the client never returns...

Is there a way to abort such a call after a timeout? Or can I abort a call programmatically? The server seems to wait endlessly for the client to return. I've decoupled the part calling Invoke() from the rest of the application, so the application can continue to run even if a client is hanging.

Now I'm looking for a way to kill these hanging calls.

Can anyone give me hint how to solve that problem?

Thank you in advance!

Greetings,
Metacrawler
ASKER CERTIFIED SOLUTION
Avatar of itsmeandnobodyelse
itsmeandnobodyelse
Flag of Germany image

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 Metacrawler

ASKER

Hello itsmeandnobodyelse,

thank you for your response. I thought terminating the thread hanging at the Invoke() is the only way to handle a hanging client, too. But there must be way to tell COM how to handle a hanging connection. That problem is not that rare, so there must be another way to abort the call.

It's a difficult problem, I know. But that's the reason why I ask you Experts :-)

Greetings,
Metacrawler

PS: I'll increase the number of point to 500. So feel encouraged to find a solution ;-)
>>>> But there must be way to tell COM how to handle a hanging connection.

The good (or bad) with COM is that you got a pointer pointing directly to a function in the COM Server which you now can use to call other functions directly via pointer as well. So, AFAIK, there is no *instance* which was watching that and could *break* in case of hanging. You don't have such a mechanism when calling your own functions either.

You also should see that only a few COM servers actually will establish connections which might hang after. It isn't the task of the COM to prevent from hanging. It is the COM method you were calling which should provide a timeout or which you need to call in a thread to prevent from freezing the main thread.
Ok, I understand.

But since I don't know how the clients are implemented, I don't know how a client behaves in some situations. The implementation of the server is the only thing I can influence. So I must rely on the clients implementation - I don't control - doing everything right... That is something causing my brain to ache ;-)

The server does some critical tasks and should continue to operate normally - even if a client does something really stupid ;-)

Greetings,
Metacrawler
I've implemented the solution with TerminateThread() and it seems to work properly.

Thank you for your assistence, the points are yours :-)