在 .net 中设置无头属性
在java中,您可以将“headless”标志设置为true,以协调无头服务器环境和桌面开发环境之间的差异。
System.setProperty("java.awt.headless", "true");
因此,每当您尝试执行无头环境中不支持的操作时,VM 都会抛出异常。
我可以修改哪些设置或标志来模拟在 IIS 应用程序池而不是本地 .NET VM 中运行的应用程序?
编辑:为了澄清我的意图,我将使用调用 System.Windows.Forms.dll、WindowsBase.dll 等的代码以及可能实例化窗口的 openGL 包装器 OpenTK。
In java you can set a "headless" flag to true to reconcile the differences between a headless server environment and your desktop development environment.
System.setProperty("java.awt.headless", "true");
So whenever you try to do an operation not supported in a headless environment the VM throws an Exception
What are the settings or flags I can modify to simulate my application running in an IIS app pool instead of the local .NET VM?
Edit: to clarify my intentions, I am going to use code that calls System.Windows.Forms.dll, WindowsBase.dll etc and the openGL wrapper OpenTK that might instantiate a window.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,本地虚拟机不会距离您很远(假设您托管在某种网络服务器中),但说实话 - 为什么要模拟? 托管在 IIS 中;没关系。为了检查细微的服务器操作系统问题,我在虚拟机中运行服务器操作系统并对其进行部署/远程调试等。
要在运行时检查,您可以检查Environment.UserInteractive;大多数基于服务的代码将报告 false - 其中 winforms 等将返回 true。
IMO,但这很少是一个问题。
Well, the local VM won't be miles out (assuming you're hosting in some kind of web-server), but to be honest - why simulate? Host it in IIS; that is fine. To check for subtle server OS issues, I run a server OS in a VM and deploy / remote-debug etc to that.
To check at runtime, you might check
Environment.UserInteractive
; most service-based code will report false - where-as winforms etc will return true.IMO, this is rarely an issue, though.
如果您希望在实例化窗口时不编译代码,只需不要引用 System.Windows.Forms.dll (WinForms) 或 WindowsBase.dll (WPF) 。
If you want your code not to compile if you instantiate a window, simply don't reference
System.Windows.Forms.dll
(WinForms) norWindowsBase.dll
(WPF).