How to detect if I'm running in mono-service?

为君一笑 提交于 2019-11-30 04:25:53

问题


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") 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.


回答1:


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 ;)

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.




回答2:


if (Environment.OSVersion.Platform.Equals(PlatformID.Unix)) 
{
}


来源:https://stackoverflow.com/questions/9065065/how-to-detect-if-im-running-in-mono-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!