C.M.W.
C.M.W.

Reputation: 145

Start windows form application from Windows service

I have created a Windows Service in which I want to start my Windows Form application. In that application I have set the form border style to FixedToolWindow also when minimized it is not shown in taskbar (I have set ShowInTaskbar to false). So I am not getting how to start that application. When I used a simple windows form application, it starts and process is shown in TaskManager but the GUI doesn't show up.

I have written following code in OnStart() method to do that. Please suggest a better solution. Also why the other simple applications UI is not shown?

p.StartInfo.FileName = @"Exe path";
p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
p.StartInfo.CreateNoWindow = true;
p.Start();

Where p is the object of System.Diagnostics.Process class.

Upvotes: 0

Views: 2717

Answers (1)

vgru
vgru

Reputation: 51322

Windows Services do not run in the same session as the logged-in user, and this is not the way to do it. You usually have a long running service in the background, and then either:

  1. user manually starts an app which can configure the service, or

  2. have a already running (tray) app, probably started when user logs in, which can be signaled by the service to wake up.

For the second case, you can use an EventWaitHandle if you only need to send a simple "wake up" call, or use whatever interprocess communication options you want for more complex data exchange. The latter are usually based on sockets or named pipes, either directly or through WCF, Remoting, or some other handy technology.

Upvotes: 2

Related Questions