开发者

am i in console app?

开发者 https://www.devze.com 2023-01-28 21:03 出处:网络
is there a way 开发者_StackOverflow社区to detect inside the component in C# if the application that uses this component is running in console application or others?Use Environment.UserInteractive. If

is there a way 开发者_StackOverflow社区to detect inside the component in C# if the application that uses this component is running in console application or others?


Use Environment.UserInteractive. If true you are in a console. If false you could be in a service.


Please see this example for your solution: http://weblogs.asp.net/whaggard/archive/2004/08/30/223020.aspx


The information you need is a property of your exe assembly. If you use a tool such as ildasm.exe to view your assembly's manifest, you can see the .subsystem property that indicates the type of execution environment that launches your Main method.

However, it seems like Reflection doesn't expose this info directly.

The code in the following link contains an example for how to read the .exe file itself and detect this infromation:

http://blogs.msdn.com/b/kstanton/archive/2004/03/31/105060.aspx

I hope this helped.


Reflection is one of the first places I would look -

http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getexecutingassembly.aspx

Q: How "sure" do you need to be?

0

精彩评论

暂无评论...
验证码 换一张
取 消