ContextSwitchDeadlock在运行单元(集成)测试时

时间:2009-08-28 08:42:20

标签: c# wcf deadlock

在test:

运行时出现以下错误
ContextSwitchDeadlock was detected
Message: The CLR has been unable to transition from COM context 0x344b0c0 to COM 
context 0x344b230 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.

测试对服务层上的方法执行WCF调用,该方法使用Entity Framework从数据库获取数据。使用EntLib缓存应用程序块在服务器端缓存数据。

在服务器端测试相同代码的测试没有错误地通过。

1 个答案:

答案 0 :(得分:1)

发现问题。

我们没有正确关闭WCF代理。我们使用“使用”而不是使用close或abort的try catch。

因此,一次测试中的错误会导致后续测试中的ContextSwitchDeadlock尝试使用相同的WCF服务。