Windows service. Showing a dialog box

C

Claire

I've written a Windows Service application that monitors input through a com
port.
It's been requested that I add a dialog box so that, should anyone need to
watch the input for troubleshooting reasons, they can.
I remember that I had to call a version of the MessageBox() function that
uses MessageBoxOptions = "ServiceNotification" on one occasion because it
was being called in context of a service application.
Are there any special procedures I have to follow for showing a user defined
dialog from a service?
 
N

Nicholas Paldino [.NET/C# MVP]

Claire,

Generally speaking, this is a VERY bad idea. Performing UI operations
from a service is very bad practice. The reason for this is that you can
not guarantee that a service will actually have an interactive user session
to show the messagebox to.

If anything, you should have some way of communicating with the service.
The easiest way to do that is to expose an object through remoting. Then,
you can have an agent that runs on another machine (or the same machine),
which can connect to the service through remoting, and be notified when
necessary. The agent would then show the UI.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top