Solved

Best way to cleanly terminate a hanging com interop call

Posted on 2004-09-30
3
222 Views
Last Modified: 2012-05-05
I'm calling a 3rd party COM+ component from a C# program via the COM interop library.  To accomplish this, I've added a reference to the 3rd party library to my C# project.   The code looks something like this:

ThirdPartyClass myObj = new ThirdPartyClass();
myObj.ThirdPartyMethod ("myFile.JPG");    // call 3rd party method

The 3rd party component is an image processing library.  Every now and then the call to ThirdPartyMethod "hangs" if  I call it with a corrupt JPEG file.  (I know the file is corrupt because both Picture Viewer and Paint display an error when they try to open it).   I'm processing a ton of images and every now and then one of them will cause this problem.  I'm working with the vendor to get the problem fixed.

In the meantime....  is there any way I can safely timeout and abort the ThirtdPartyMethod call? The obvious thing to do is to wrap the ThirdPartyMethod call in a separate thread, set a timer and abort the thread when the timer pops.  But I wonder how that affects the process which is hosting the COM object?  I would think that it would continue to process the method call which means that I've just moved the problem rather than solved it.

0
Comment
Question by:wile_e_coyote
[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
  • 2
3 Comments
 
LVL 18

Expert Comment

by:armoghan
ID: 12197692
You can do these lines in a thread

ThirdPartyClass myObj = new ThirdPartyClass();
myObj.ThirdPartyMethod ("myFile.JPG");    

and start a timer in the main thread, if the response doesnot come from the thread in a given interval, distroy the thread
0
 
LVL 4

Author Comment

by:wile_e_coyote
ID: 12198785
armoghan - Thanks and I agree, but as I understand the COM Interop architecture (and maybe I'm confused), the 3rd party component is actually being hosted in a separate process.  When the thread is destroyed does the component continue to execute anyway?
0
 
LVL 18

Accepted Solution

by:
armoghan earned 500 total points
ID: 12199086
Yes may be !. But it will not hang your system atleast, and garbage collector will take that object away..
If there is no way in COM object that this is the best you can do ..


Unless and untill the third party COM has provided it as multithreaded or some async mechanism to stop it
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 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