am i in console app?
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?
精彩评论