Microsoft .NET Security Warning

用C#.NET创建的程序,放在局域网上在另外一台电脑上打开,会出现一个提示:

Microsoft .NET Security Warning

Microsoft .NET Security Warning

GOOGLE了一下,发现这是因为在本地电脑和局域网电脑上运行程序的安全许可不同而造成的。

这里有一篇2003年的文章详细介绍了MyComupter zone和LocalIntranet zone的不同,也列出了解决的三种办法。其中第三种修改policy来完全的信任LocalIntranet zone是不被推荐的,因为是一个非常大的安全漏洞。

上面的三种办法我都没有试,因为看到这个人的另外一个2008年的文章介绍了最新的解决办法,就是安装.NET Framework 3.5 SP1在客户端,起到Full trust LocalIntranet zone的作用,在客户端运行局域网上的软件就会没有任何问题。乍看起来是跟上面说的第三种一样,但其实是不一样的。3.5SP1会起到“沙盒”的作用,这样就能有效杜绝所引发的安全漏洞。

只是3.5SP1够大的。。231MB。。

ContextSwitchDeadlock was detected

在运行C#程序的时候得到如下错误信息:

The CLR has been unable to transition from COM context 0×197060 to COM context 0×196ef0 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.

简单的修复方法是:(VS2005下) 打开 Debug -> Exceptions -> Managed Debug Assistants,

把ContextSwitchDeadlock取消勾选就可以了。