tags:

views:

310

answers:

3

Is it true that a service written in C# is unable to give visual feedback to the desktop?

I understand that services start up before user logon and at that point ther is no desktop available. My question then, apart from logging events in the system event log which is not a very efficient way of communicating to the user, what are my alternatives for showing a message box from a service?

Only two options come to mind:

  1. MessageBox.Show - Looking around it seems this is not going to be an option.
  2. Show a custom form

I've not given the reasons for why this messagebox needs to be shown. Please assume that it needs to be shown as I don't want responses on "good practice". Not at this point at least.

+3  A: 

A windows service should not perform interactions with a user. Instead you should create a seperate control or configuration application - often put into the system tray - that communicates with the service an can present information to the user or gather inputs.

See this Knowledge Base article and this MSDN article if you really want to do this. They contain some hints how to achiev this an you will probably need to use P/Invoke from C#.

Daniel Brückner
A: 

Here are some ways that you can make interactive services. But, those have gone away with Vista.

One way you can have a user get information from a service is to build a separate UI for the purpose. The service could have a WCF endpoint for example and push messages out that the GUI would show. That way, you only show a message when there is a user logged in and it's not a security risk by popping up a window from the LocalSystem account. You could easily make this GUI run from the tray and pop-up toast so it is non-intrusive and begins when the user logs in. Much much better than trying to interact directly with the desktop.

JP Alioto
A: 

I've never used it, and I include all of the disclaimers about not doing this.

However, you may want to check out the MessageBoxOptions.ServiceNotification enum.

Here's a good blog post detailing its use.

Aaron Daniels