As a rule of thumb services should never have any kind of UI, this is because services usually run with very high privileges and can bad things can happen if you are not super careful with your inputs (I think the newest versions of windows won't let you do it at all but I am not 100% sure). if you need to communicate with a service you should use some form of IPC (wcf, pipes, sockets, ect...). If you want a simple console program that also can be a service I know of a trick set that up.
class MyExampleApp : ServiceBase
{
public static void Main(string[] args)
{
if (args.Length == 1 && args[0].Equals("--console"))
{
new MyExampleApp().ConsoleRun();
}
else
{
ServiceBase.Run(new MyExampleApp());
}
}
private void ConsoleRun()
{
Console.WriteLine(string.Format("{0}::starting...", GetType().FullName));
OnStart(null);
Console.WriteLine(string.Format("{0}::ready (ENTER to exit)", GetType().FullName));
Console.ReadLine();
OnStop();
Console.WriteLine(string.Format("{0}::stopped", GetType().FullName));
}
//snip
}
if you just start the program it will launch as a service (and yell at you if you run it from the console) but if you add the paramter --console
when you start it the program will launch and wait for you to hit enter to close.