show a windows form from a window service

i am creating a window service. my requirement is to display window form from window NT service on particular interval. For testing purpose , i just want to display the form on service start:

 protected override void OnStart(string[] args)
        {
            eventLog1.WriteEntry("In OnStart -before form show");

            Messager_Form obj = new Messager_Form();
            obj.Show();
           // System.Diagnostics.Process.Start("calc.exe");
            eventLog1.WriteEntry("In OnStart -after form show");
           // timer1.Start();
        }

it not working. Neither form is showing nor calc process is running. i have found some links showing pop up , but most of them suggesting WCF. isn't it possible without wcf. can anybody show me the way to achieve this.


Solution 1:

Cant be done*. In later Operating Systems that won't work as Windows Services are disallowed from interacting with the Desktop - instead UI presented by Windows Services is shown in Session 0, a special logon session which is not normally visible to the end user.

What you should instead do is write a separate Windows Forms application which is always running, but not always visible (possibly have that application run at startup and have an icon in the notification area) and communicates with the Windows Service using some form of IPC

When the Windows Service wishes to display some UI to the user it sends a message to the application, which in turns shows the desired UI to the end user.

**or at least it definitely shouldn't be done*

Solution 2:

I am just referring to the answer given in another link in StackOverflow

How to communicate with a windows service from an application that interacts with the desktop?

Answer is :

Be aware that if you are planning to eventually deploy on Windows Vista or Windows Server 2008, many ways that this can be done today will not work. This is because of the introduction of a new security feature called "Session 0 Isolation".

Most windows services have been moved to run in Session 0 now in order to properly isolate them from the rest of the system. An extension of this is that the first user to login to the system no longer is placed in Session #0, they are placed in Session 1. And hence, the isolation will break code that does certain types of communication between services and desktop applications.

The best way to write code today that will work on Vista and Server 2008 going forward when doing communication between services and applications is to use a proper cross-process API like RPC, Named Pipes, etc. Do not use SendMessage/PostMessage as that will fail under Session 0 Isolation.

http://www.microsoft.com/whdc/system/vista/services.mspx

Now, given your requirements, you are going to be in a bit of a pickle. For the cross-platform concerns, I'm not sure if Remoting would be supported. You may have to drop down and go all the way back to sockets: http://msdn.microsoft.com/en-us/library/system.net.sockets.aspx

Solution 3:

Checking the "Interact with desktop" box will work on Windows NT, 2000, XP and 2003 but thanks to Session 0 Isolation that setting no longer works as you may expect in Windows Vista and beyond. You want to think very carefully before developing an interactive service...