2010-09-01 87 views
0

我正在使用互操作調用COM DLL的Windows窗體應用程序。 我一直得到在應用此方法錯誤的流動是這樣的:如何擺脫COM上下文錯誤

1.Fetch從數據庫 2.對於每此記錄的約7記錄[R],應用程序使用互操作實例化一個COM類和不一些使用相同的處理/計算。 3.Then應用程序獲取約750記錄每此記錄的R. 4.App然後更新回的數據在數據庫中的每個記錄在步驟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. 

僅供參考,我使用System.Runtime .InteropServices.Marshal.ReleaseComObject來釋放COM對象實例。 任何想法,如何擺脫這個?請建議。

謝謝。

回答

1

你是COM對象的所有者嗎?你的解決方法將改變其線程模型,或者看看here,特別是關於Release的部分。

0

我曾經得到這個錯誤,但只有當我在調試模式。你是否也在釋放模式下發生錯誤?

+0

Thanks for your comment.Well,am get it in it only mode only.Does it because because a running running process?多線程/異步調用會解決問題嗎? – Jimmy 2010-09-06 10:37:19

+0

我以前只是點擊「確定」,過程會恢復。這很煩人,但我從來沒有找到解決方法。 – 0x4f3759df 2010-09-06 14:48:36