Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. NotifyIcon for a Service

NotifyIcon for a Service

Scheduled Pinned Locked Moved C#
beta-testinghelptutorialquestioncode-review
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    occcy
    wrote on last edited by
    #1

    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

    S D 2 Replies Last reply
    0
    • O 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? occcy

      S Offline
      S Offline
      Stanciu Vlad
      wrote on last edited by
      #2

      mabye I am wrong but i think that you should put the NI variable at the calss level. In the code exemple supplied by you NI will be removed (by the garbage colector) at the end of the OnStart function scope. I hope you understand... By the way... visit http://nehe.gamedev.net[^]

      1 Reply Last reply
      0
      • O 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? occcy

        D Offline
        D Offline
        Daniel Turini
        wrote on last edited by
        #3

        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!

        O 1 Reply Last reply
        0
        • D Daniel Turini

          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!

          O Offline
          O Offline
          occcy
          wrote on last edited by
          #4

          Okay! That sounds plausible ;-) Thanks! occcy

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups