Solved

How to abort a call to a COM method?

Posted on 2009-07-02
5
921 Views
Last Modified: 2013-12-14
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
0
Comment
Question by:Metacrawler
  • 3
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 500 total points
ID: 24763153
You could put the Invoke to a thread and call TerminateThread if it timeouts. However, that probably will let open some resources and - depending on the actions done by the COM - even could corrupt your system (e. g. if some data halfly were written to a file). So, the TerminateThread should be the last resort and if you could move the termination into the COM method it would be better. Best would be if only the last hanging action was put into a own thread which was killed after timeout. Then, the dangers can be managed or even ignored. E. g. if the hanging action is the attempt to connect to a server, you could terminate that action without probs as the TCP/IP subsystem is safe regarding dying clients.
0
 

Author Comment

by:Metacrawler
ID: 24770486
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 ;-)
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 24770730
>>>> 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.
0
 

Author Comment

by:Metacrawler
ID: 24770810
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
0
 

Author Comment

by:Metacrawler
ID: 24771491
I've implemented the solution with TerminateThread() and it seems to work properly.

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
post4 challenge 28 105
fix34  challenge 9 148
Problem to Alipay 10 48
what is the best Integrated development environment 2 21
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

820 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