0

we have an .NET application which uses a COM dll, the ThreadingModel of this component is "Appartment"

The Application always hangs calling a COM interface method.

the DebugDiag analysis says the following

The finalizer thread is probably tring to release an instance of an STA COM component, and it is stuck waiting for the STA thread to become available. To resolve this problem, call Marshal.ReleaseComObject to clean up the references for all apartment-threaded COM components that you have used in your code deterministically (immediately), rather than waiting for the Finalizer Thread to do it at a later time.

in the recommendation section, it has recommended to change the threading model to "Both" which i did and was working fine, but this cannot be done as we have an UI and is not recommended as per our design.

any idea what changes in our .NET application code can fix this issue.

Stack trace there are two threads, 2 and 65 that are trying to call into the COM object which in on thread 45, i guess the STA thread call stack of thread 2

enter image description here

call stack of thread 65

enter image description here

user2101801
  • 719
  • 2
  • 8
  • 20
  • Not very likely that the DebugDiag message is accurate, you are still using the object. You'll have to give us a look-see, at least the full stack trace of the hung call. – Hans Passant Sep 25 '17 at 18:10
  • added the call stack information , thank you for looking into this – user2101801 Sep 26 '17 at 05:52
  • Well, the DebugDiag message was accurate, the finalizer thread is deadlocked. The second thread is not happy either, probably for the same reason. Whatever STA thread owns the object (not visible) is no longer doing its duty, running the dispatcher. Never block an STA thread. With some luck you'll see it when you look at the UI thread, it is doing something unwise like waiting for that worker thread that calls get_Data() to complete. – Hans Passant Sep 26 '17 at 06:02

0 Answers0