Windows Service and notyfication icon...

J

Jacek Jurkowski

I would like to make a notyfication icon showing
all the time my service is running ... The problem is
that in implementation above requires to check
"Allow interact with desktop" in service properys
tab to work properly ... Why? How to make my
notyfication visible without doing anything manually?

Here's my code...
#region Using directives

using System;

using System.Data;

using System.Text;

using System.Diagnostics;

using System.Windows.Forms;

using System.ComponentModel;

using System.ServiceProcess;

using System.Collections.Generic;

#endregion

namespace Datacomp.FelixService

{

/// <summary>

/// Serwis Windows Felix.

/// </summary>

public partial class FelixService : ServiceBase

{

#region Members

NotifyIcon nI;

#endregion

#region Constructor

/// <summary>

/// Serwis Windows Felix.

/// </summary>

public FelixService()

{

InitializeComponent();

}

#endregion

#region OnStart

/// <summary>

/// Gdy serwis startuje.

/// </summary>

/// <param name="args">Argumenty startu serwisu.</param>

protected override void OnStart(string[] args)

{

nI = new NotifyIcon();

nI.Icon = Properties.Resources.Main;

nI.Text = "Serwis Felix jest uruchomiony...";

nI.Visible = true;

}

#endregion

#region OnStop

/// <summary>

/// Gdy serwis zostaje zatrzymany.

/// </summary>

protected override void OnStop()

{

nI.Visible = false;

nI.Dispose();

nI = null;

}

#endregion

}

}
 
B

Bob Powell [MVP]

NotifyIcon is a GUI element and needs a window, even if it can be a hidden
window, to process messages. Only services that run with no GUI whatsoever
can be used without the "interact with desktop" setting.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 

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