在 .net 中设置无头属性

发布于 2024-08-12 09:27:15 字数 338 浏览 5 评论 0原文

在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜`诱少女 2024-08-19 09:27:15

模拟我的应用程序在 IIS 应用程序池而不是本地 .NET VM 中运行?

好吧,本地虚拟机不会距离您很远(假设您托管在某种网络服务器中),但说实话 - 为什么要模拟? 托管在 IIS 中;没关系。为了检查细微的服务器操作系统问题,我在虚拟机中运行服务器操作系统并对其进行部署/远程调试等。


要在运行时检查,您可以检查Environment.UserInteractive;大多数基于服务的代码将报告 false - 其中 winforms 等将返回 true。

IMO,但这很少是一个问题。

simulate my application running in an IIS app pool instead of the local .NET VM?

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.

嘿咻 2024-08-19 09:27:15

如果您希望在实例化窗口时不编译代码,只需不要引用 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) nor WindowsBase.dll (WPF).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文