VS在Debug时检测到Loaderlock的解决办法
用VB .net 2008写一段录音程序,碰到一个问题:
安装了directx 后,调试过程
LoaderLock was detected
Message: DLL '.......\Microsoft.DirectX.Direct3D.dll' is attempting
managed execution inside OS Loader lock. Do not attempt to run
managed code inside a DllMain or image initialization function since
doing so can cause the application to hang.A Loader lock is one of the Managed Debugging Assistants (MDAs) that were added to VS2005 to help find hard to debug runtime issues. There is code in all Managed DirectX 1.1 assemblies that causes this MDA to fire. Microsoft have confirmed they are aware of the problem. However I do not expect to see a fix for MDX 1.1 since current efforts are focused on MDX2.0/XNA Framework, it ONLY affects code run under the debugger (i.e. it won't happen when users run your EXE) and there is a trivial workaround. I'm not sure of exact reproduction steps - it appears to fire on some projects and not on others.
出错代码位置如下:
//打开一个新的Video文件
myVideo = new Video(openFileDialog1.FileName);
去网上查了一下资料:.NET2.0中增加了42种非常强大的调试助手(Loaderlock是其中之一。Loaderlock检测在一个拥有操作系统loader lock的线程上(如上例的video的运行线程)运行托管代码的情况。这样做有可能会引起死锁,并且有可能在操作系统加载器初始化DLL前被使用。虽然这样做很有必要,但在进行开发调试的时候,实在太麻烦。解决方案如下:
1.改注册表
在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework下面增加一个String,值为"0"
不过这样做,在该计算机上所有基于.NET2.0开发都得不到MDA的好处。
2.为项目增加一个配置文件.
3.直接修改项目设置
最简单的方法,在"Debug"菜单下----"Exceptions"----"Managed Debugging Assistants"中勾掉"LoaderLock")
阅读(6604) | 评论(0) | 转发(0) |