Re: How do I manually create an icon in the system tray?



On Thu, 05 Jul 2007 13:00:46 -0700, Joseph Geretz <jgeretz@xxxxxxxxxx> wrote:

Hmmm...I thought that services by definition were not allowed to have UI.
That would preclude the service itself from using the system tray for a
notify icon.

Is this really true? I have about a dozen icons in my Tray, about half of
them represent running services (e.g. PCAnywhere, SQL Server, Bluetooth,
etc.).

I'll reiterate: I don't really know much about writing services. :) I do _use_ them all the time though.

That said, my understanding is that the "dozen icons in your Tray" are the UI side of the services, not put there directly by the service process. Services can (and usually do) start without there being a logged in user or any GUI available. So services by themselves wouldn't be able to present a user interface, not being able to know in advance if there is even a way to do so.

I suspect that for each of those icons in your task tray, there is a user-side process somewhere that talks to the service for the purpose of controlling it. You should be able to look in the Task Manager process list (or use SysInternals Process Explorer, which provides more detailed information) and identify processes that are services vs. processes that are running in your logged in user's space. It is likely that you could terminate the user-side process, without affecting the service, but resulting in the loss of the task tray icon (you'll have to mouse over it first to see it disappear, as the icons aren't removed until Windows tries and fails to actually contact the process that put it there).

Writing a service is a bit of a black art from what I can see;

Oh, I don't know about that.

Well, actually...I _literally_ don't know about that. Still, I don't see what's so difficult about it. Perhaps I'm simply speaking from inexperience, but I don't see why a service should be any different from any other process, except that there's no user interface. I mean, I realize there may be particular things a service is required to implement, things that actually make it a service. But otherwise? I don't see what would make it so arcane.

Since a
service won't run in the IDE it's difficult to step through the code during
the development in order to test it.

I didn't realize that a service won't run in the IDE. Can you elaborate on that?

In any case, I would guess that remote debugging might be useful in that scenario. That's what I use when I'm trying to debug something that for whatever reason doesn't work when the process is started from within the IDE (as an example, debugging drawing code is pretty challenging without remote debugging, since every time you step in the debugger, focus switches from the application back to the debugger, forcing new redraw events and invalidating existing drawn graphics).

Also, I have seen people here mention that they do essentially what you've done, with respect to debugging. A common technique seems to be making the service a console application for the purposes of debugging, then removing the small console wrapper required when actually deploying the service.

[...]
Are there any whitepapers which describe logistics and best-practices for
service development using Visual Studio 2005? I am managing, but if there
are specific recommendations and approaches which work better than others,
I'd like to read up on them.

Hopefully someone with more experience with writing services can answer that question. I think it's likely there are documents on MSDN for it, but don't know off-hand where they are.

Pete
.



Relevant Pages

  • Re: How do I manually create an icon in the system tray?
    ... A service application simply won't execute in the IDE ... which makes it difficult to work with while developing / debugging. ... That would preclude the service itself from using the system tray for a ... my understanding is that the "dozen icons in your Tray" are the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Taskbar acting up.
    ... Windows? ... What you are describing sounds like the 'hide inactive icons' feature ... the Taskbar. ... Because so many applications use the tray, ...
    (microsoft.public.windowsxp.customize)
  • Re: My System Tray is missing.
    ... I'll sign off again then back in to see if the Sys Tray ... clock" then below is the "Hide inactive icons" checked or unchecked? ... icons check box. ... On the Taskbar tab, ...
    (microsoft.public.windowsxp.general)
  • Re: Taskbar acting up.
    ... various icons into the tray for a quick start. ... Perhaps you are not using an English version of Windows? ... the Taskbar. ... Because so many applications use the tray, ...
    (microsoft.public.windowsxp.customize)
  • Tray icon boot order - network icon taking ages to initialise
    ... Any suggestions as to how to reconfigure the order that tray icons load ... under Windows XP Home? ... connection takes ages to appear in the system tray (as much as a minute ...
    (alt.comp.hardware.pc-homebuilt)