C# C/S程序出错:ContextSwitchDeadlock is detected
今天在VS2005调试一个C# C/S程序,当通过RFC与SAP连接时间过长时,出现此错误,在网上找到解决办法。
VS2008上的一个程序,通过Oracle.DataAccess.dll执行drop user
cascade操作,我在sqlplus执行此操作大约需要一分钟左右时间,当我在VS2008中debug启动此程序时,一直接收到
“ContextSwitchDeadlock is detected”消息,操作无法进行下去。
MSDN的解释一如即往地专业并且令人费解:
“如果在试图进行COM上下文转换期间检测到一个死锁,则将激活ContextSwitchDeadlock托管调试助手 (MDA)。 ”
“原因很可能是单线程单元(STA)线程不发送消息。STA线程或者等待而且不发送消息,或者执行一个长时间的操作而且不允许发送消息队列。”
我没看出这程序跟COM有什么关系。看了半天,只看到“长时间的操作”貌似还沾点边,解决的方法倒是简
单,Debug->Exceptions->Managed Debugging
Assistants->ContextSwitchDeadlock,钩除“Thrown”项的复选框。
BTW,
1)COM,Component Object Model,它实际是一类软件开发方式。而COM组件顾名思义是按这种方式开发出来的软件/模块,看看Project->References->Add References->COM下列出的组件。
2)单线程单元(STA):当你新建一个WindowsForm项目,在入口Main()方法上可以看到标识的属性,STAThread说明应用程
序的 COM 线程模型是单线程单元,一般出现在Main方法前。大意是在与COM互操作时保证对象的线程安全性,内部细节不详。
相关文档:
Windows C 程序设计入门与提高
http://download.chinaitlab.com/program/files/13246.html
单片机C语言入门
http://download.chinaitlab.com/program/files/12907.html
C++ 入门基础教程
http://download.chinaitlab.com/program/files/7617.html
C语言常用算法源代码
http://download.chinaitlab.com/program/files ......
以下是几个棘手的
C 问题, 很难做, 看看自己会做几个?
How do you write a program which produces its own source code as its output?
How can I find the day of the week given the date?
Why doesn’t C have nested functions?
What is the most efficient way to count the num ......
C/C++语言实现动态数组
C数组的小问题
这里说的动态数组是可以根据需要动态增长占用内存的数组,比如程序初始分配了100个元素,可是运行了一段时间后区区100个空间不能满足了,现在需要400个,怎么办呢;那肯定需要再额外分配300个。
C语言有realloc()函数来解决空间 ......
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Default" value="Default" />
</appSettings>
<connectionStrings>
<add name="Default" connectionString="Data Source=192.168.1.197;User ID ......