views:

59

answers:

1

How to determine whether code is getting executed in a console app or in a windows service?

+3  A: 

Whilst it's not console specific (i.e. this will return true when running as a winforms app as well) I've used the following

if (Environment.UserInteractive)
{
    Console.WriteLine("Hi I'm being ran as a console app");
}
blowdart