NotifyIcon in windows service

torisch

Newcomer
Joined
Jan 23, 2003
Messages
11
Location
Tromsø - Norway
Hi!

I have made a windows service application. I try to put a NotifyIcon in the system tray when the service is running, but it does not display.

I have the following code in my OnStart Sub:
Code:
Protected Overrides Sub OnStart(ByVal args() As String)
        ' Add code here to start your service. This method should set things
        ' in motion so your service can do its work.
        Dim trayItem As System.Windows.Forms.NotifyIcon = New System.Windows.Forms.NotifyIcon()
        trayItem.Icon = System.Drawing.SystemIcons.Question
        trayItem.Visible = True
End Sub

The service is installing and starting OK, but the icon never appear in my system tray. I'm not very in to services, so if anyone can tell me what I'm doing wrong I will be a happy man!

Thanx!
__
Tor Inge
 
Recurring Question

This seems to be a recurring question, and I am having the same issue.

From my understanding the issue is that a service runs in the System
context, which prevents it from displaying items in the system tray in the
current user context. This is also preventing any windows being shown.

e.g.
myForm _newForm = new myForm();
_newForm.Show();


However, no one has given a clear method of the desired functionality.

How do you show an icon or form from a service?

It has been suggested that there needs to be an application run in the
current under context, but how does this get initiated from the service
when Windows starts?

Or does the service get initiated from the main application?

But then how do they talk to each other?

A push in the right direction (in C# :cool: ) would be nice. I have been
bouncing around this for a couple of days, and I am sure there is a way
to open the form in the current user context, but after the number of
crashes and locked up services I have had, some help would be useful.

Cheers
Karl Rohde
 
To fix the problem try the following:
Open the Service manager.
Open properties for the service.
check the checkbox "Allow Service to interact with desktop"

This should allow the NotifyIcon to be shown.

/Niclas Sparr
 
Back
Top