Solved

How to abort a call to a COM method?

Posted on 2009-07-02
5
915 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Specific format 21 181
java. non-English characters encoding problem. intellij idea 3 73
Angular JS Route 3 45
oracle 11g 23 47
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
This article will show, step by step, how to integrate R code into a R Sweave document
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

914 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now