NotifyIcon for a Service
-
Hi! I've written a windows service. This service can be in different states, for example running, paused, updating etc. To give the user a direct feedback of the services state, I want to display an icon on the windows system tray, which appears in different kind for each state...... The problem is, that the icon (System.Windows.Forms.NotifyIcon) is not displayed... but also no exception is thrown...
protected override void OnStart(string[] args) { //... NotifyIcon NI=new NotifyIcon(); NI.Icon=new Icon(@" ... "); //<- Path to an icon file NI.Text="My Service"; NI.Visible=true; //... }
Can somebody tell me, why my NotifyIcon is not displayed? occcy -
Hi! I've written a windows service. This service can be in different states, for example running, paused, updating etc. To give the user a direct feedback of the services state, I want to display an icon on the windows system tray, which appears in different kind for each state...... The problem is, that the icon (System.Windows.Forms.NotifyIcon) is not displayed... but also no exception is thrown...
protected override void OnStart(string[] args) { //... NotifyIcon NI=new NotifyIcon(); NI.Icon=new Icon(@" ... "); //<- Path to an icon file NI.Text="My Service"; NI.Visible=true; //... }
Can somebody tell me, why my NotifyIcon is not displayed? occcymabye I am wrong but i think that you should put the
NI
variable at the calss level. In the code exemple supplied by youNI
will be removed (by the garbage colector) at the end of theOnStart
function scope. I hope you understand... By the way... visit http://nehe.gamedev.net[^] -
Hi! I've written a windows service. This service can be in different states, for example running, paused, updating etc. To give the user a direct feedback of the services state, I want to display an icon on the windows system tray, which appears in different kind for each state...... The problem is, that the icon (System.Windows.Forms.NotifyIcon) is not displayed... but also no exception is thrown...
protected override void OnStart(string[] args) { //... NotifyIcon NI=new NotifyIcon(); NI.Icon=new Icon(@" ... "); //<- Path to an icon file NI.Text="My Service"; NI.Visible=true; //... }
Can somebody tell me, why my NotifyIcon is not displayed? occcyA service should not interact with the desktop unless unavoidable, because it could introduce some serious security issues. A sounder design would be the service "talking" to another program that displays the icon. Don't forget that services run even when there is no desktop, i.e., when no user is logged in. If you really must do it, there's the "allow service to interact with the desktop" checkbox on the service manager, but I strongly advise you not to use it, unless it's only test code... Yes, even I am blogging now!
-
A service should not interact with the desktop unless unavoidable, because it could introduce some serious security issues. A sounder design would be the service "talking" to another program that displays the icon. Don't forget that services run even when there is no desktop, i.e., when no user is logged in. If you really must do it, there's the "allow service to interact with the desktop" checkbox on the service manager, but I strongly advise you not to use it, unless it's only test code... Yes, even I am blogging now!