Is there a way to open a windows form from a windows service?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am monitoring certain events with a windows service
(derived from System.ServiceProcess.ServiceBase).
When a significant event comes up, I'd like to notify
the user with a pop-up dialog box or window.

In my event handler, I create a new thread, inside
which, I have:

MyForm frm = new MyForm();
System.Windows.Forms.Application.Run( frm );

I am able to step into the form initialization and load code,
but I never see the form on the screen. I also don't get
any errors.

What am I doing wrong?
 
Hi Alexander,

Alexander Feygin said:
I am able to step into the form initialization and load code,
but I never see the form on the screen. I also don't get
any errors.

What am I doing wrong?

Nothing, Windows services are just not designed to have any User Interface
because they run in the background regardless if a user is logged in or not.
Actually, it is possible to display a user interface from a Windows Service
but it is highly not recommended as it is like giving administrator rights
to any user on the machine (and this is just a subset of the problems you'll
have if you persist in this direction).

The recommended way is to have a normal Windows application that
communicates with the Windows service in some way (for example via .NET
Remoting) and is in charge of displaying the user interface. This windows
application can be placed in the startup folder so that it is launched
automatically each time a user logs in. Have a look as this article for some
general information:
http://support.microsoft.com/default.aspx?scid=kb;en-us;308403
 
Back
Top