Windows Services in VS.NET

This is a discussion on Windows Services in VS.NET within the C# Programming forums, part of the General Programming Boards category; In Visual C++ under Visual Studio.NET, a few quick questions: - How do I add an interface to a service? ...

  1. #1
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913

    Windows Services in VS.NET

    In Visual C++ under Visual Studio.NET, a few quick questions:

    - How do I add an interface to a service? Take MSN Messenger for example. It has an icon running in the tray (while I'm on the subject, what do I have to do to my service to get that icon in the tray?), and when you click on it (or right-click for a menu), a form pops-up. By definition, a service does not have an interface, so I was thinking that it might not be as simple as adding a form to the project and making an event handler call it's "show" function.

    - I figured out quite quickly where to add my start up and close down code (the function names onStart and OnClose gave it away), but where do I put the code I want the service to be executing in the background.

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Actually change that to C# - not Visual C++. I know this isn't a C# board, but anybody have anything to say nonetheless?

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    I wouldn't classify a messenger program as a service. A service is soemthing that can run independently of any logged on user. If a service has a user interface, I guess it could be implemented in two ways: service access to the desktop or simply another program that communicates with the service by tcp/ip or some other protocol.

    You can start a thread in the startup method if you need continuous execution.

    Sorry, I'm just making a slightly educated guess here, I never did more than play around with services
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Alright, well then maybe a service isn't the best template for me to go with. Maybe someone can suggest a better approach. I'm making an anti-virus program (yeah - I know about the deck being stacked against me - it just sounded fun and I had a good idea on how to go about the actual virus detection, so I thought I'd try it out). I'd like it to have the following:

    - Accesible from the system tray

    - Have an interface (I can do this for a regular app easily, but does this change for services or similar projects?)

    - Run in the background (Any way to do this without a service?)

    - Start automatically at logon or during the boot.

    Can anyone enlighten me as to where I might find some answers on any of these? I've been combing all the walkthrough that come with the MSDN CDs, but so far, nothing is all that helpful.

  5. #5
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    - Accesible from the system tray

    Use a trayicon and make the form itself invisible on minimize.
    The trayicon has it's own .NET class called NotifyIcon. It's a component you can drop on a form.

    - Have an interface (I can do this for a regular app easily, but does this change for services or similar projects?)

    If you seriously need a service, you could either have it access the desktop, or write a standalone application like normal that uses some communication protocoll ( tcp maybe ) to communicate with the service.

    - Run in the background (Any way to do this without a service?)

    If you minimize a programm, it's still running. If you don't need any fancy service things like running without a user logged on, then I guess a normal application would suffice.

    - Start automatically at logon or during the boot.

    Put it in autostart for all users.



    Matter of fact, if you write your application and engine modular, you should have no problem seperating it into a service component ( Engine ) and application ( user interface ) later on if you find out that you indeed need a service.
    However, for writing the core parts, writing and debugging a service would be too much work. If you need it to be a service, write good code and it shouldn't be a problem later on
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  6. #6
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Awesome - thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  2. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 10:59 AM
  3. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  4. Newb Alert! ----> BOOGIEMAN
    By BOOGIEMAN in forum C++ Programming
    Replies: 7
    Last Post: 10-10-2003, 03:25 PM
  5. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 06:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21