tags:

views:

40

answers:

2

Hi,

Am working on a windows form application which uses interop to call a COM dll. I keep getting this error in the app method where the flow is like this:

1.Fetch about 7 records[R] from database 2.For each of this record,app instantiates a COM class using Interop and does some processing/calculation using the same. 3.Then the app fetches about 750 records for each of this record R. 4.App then updates back data in database for each record in step 3.

    ContextSwitchDeadlock was detected
    Message: The CLR has been unable to transition from COM context 0x1c8be8 to COM context 0x1c8a78 for 60 seconds. The thread that owns the destination 
    context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation 
    generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. 
To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump 
messages during long running operations.

FYI, I'm using System.Runtime.InteropServices.Marshal.ReleaseComObject to release the COM object instance. Any idea, how to get rid of this?Please suggest.

Thanks.

+1  A: 

Are you the owner of the COM object? Your workaround will either changing its threading model, or perhaps taking a good look here, especially the part about Release.

Voulnet
A: 

I used to get that error but only when I was in Debug mode. Do you get that error in release mode as well?

iterationx
thanks for your comment.Well,am getting it in debug mode only.Does it occur because of a long running process?Would multithreading/async calls solve the issue?
Jimmy
I used to just hit "ok" and the process would resume. It was annoying but I never bothered to find a workaround.
iterationx