问题描述
如何检测我在 mono-service2 下运行?(在 C#/.NET 3.5 中,在 ubuntu 11 上运行 mono 2.6.7)
How can I detect I'm running under mono-service2? (in C#/.NET 3.5, running mono 2.6.7 on ubuntu 11)
Type.GetType("Mono.Runtime")
告诉我我正在单声道运行,所以这部分没问题.但是 Environment.UserInteractive
在单声道下似乎总是错误的,所以我很难弄清楚我是否真的在单声道服务2下运行 - 没有控制台/终端.
Type.GetType("Mono.Runtime")
tells me I'm running in mono, so that part is ok. But Environment.UserInteractive
is always false under mono it seems, so I'm struggling to figure out if I'm actually running under mono-service2 - with no console/terminal.
推荐答案
Environment.UserInteractive
是正确的解决方案,但不幸的是,它目前还没有在 Mono 中实现.有一天我可能会看看它并升级这个答案;)
Environment.UserInteractive
is the proper solution but, unfortunately, it is currently not implemented in Mono. I may take a look on it someday and upgrade this answer ;)
但是,只是为了检测你可以使用 hacky 解决方案来解决这个问题:在 m
参数中赋予 mono-service
的名称将成为该应用程序域的友好名称服务(至少根据 mono-service
的当前源代码).因此,当使用此参数运行时,您应该能够测试:
However just to detect you can probably use hacky solution around this one: name given to mono-service
in m
parameter will become the friendly name of application domain of that service (at least according to the current source code of mono-service
). So, when run with this parameter you should be able to test:
AppDomain.CurrentDomain.FriendlyName == "NameGivenToMParameter"
如果是这样,那么您的应用程序显然是使用单服务(使用给定参数)运行的.将应用程序域名的值打印到文件中,看看它是否真的有效(对我有用);)我不知道它是否真的解决了你的问题.
If it is true, then your application is apparently ran with mono-service (with given parameter). Print the value of application domain name to file to see if it really works (it does for me) ;) I do not know if it really resolves your problem.
这篇关于如何检测我是否在单服务中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!