?
Solved

How to abort a call to a COM method?

Posted on 2009-07-02
5
Medium Priority
?
938 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
[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
  • 3
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 2000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilationā€¦
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called eeā€¦
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

771 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