(C#) Handling COM object with an infinite loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vitalyb
    New Member
    • Jul 2008
    • 1

    (C#) Handling COM object with an infinite loop

    I am writing a code to test a COM object and one of its functions has an infinite loop.
    Basically my code should run this COM object function in a different thread, give it some time to finish but if it doesn't, terminate it.

    However, I encountered the following problems:
    1) Thread.Abort wouldn't abort the thread because you can't use .NET Thread.Abort to abort unmanaged code.
    2) AppDomain.Unloa d wouldn't do anything because it tries to abort all the threads.
    3) I tried using Marashal.Releas eComObject and it resulted with:
    "An attempt has been made to free an RCW that is in use. The RCW is in use on the active thread or another thread. Attempting to free an in-use RCW can cause corruption or data loss."

    By now the only current options I see is either using somehow the original Windows API to abort the thread or create a process especially to test the function. Both methods seem like a lot of overkill for what I'm trying to do.

    Anyone has any ideas?
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Are you not using DllImport to use the object?

    Comment

    Working...