Compartir a través de


making a service...

Oooofda...long time no post.  Lots of work done though.  hehehe.

My question of the day...how do you make a service?  I have an executable that's a remoting server...and currently I have a Console.ReadLine(); in the code to make sure the app doesn't exist until I want it too...what I would like is for this app to sit running all the time as a service, so I don't have to see it...

So I guess my question is a 2 parter...

1) What's the best way to get an app to just sit and listen for an incoming remoting request?

2) How do you get the test .exe to run as a service in XP?  I can't seem to find anything in the OS that allows this...

anyway, I'll keep seaching the net for answers, but if anyone happens to have one of them and some free time to post, please post any advice you can offer.  :)

Comments

  • Anonymous
    September 29, 2005
    1: Use SRVANY from one of the versions of the reskit it shipped in (any since 2K, IIRC). This is suboptimal, since you have something that isn't a service running as a service - not a great idea, IMHO. If it throws UI, it can throw off the whole task.

    2: Rewrite it in .NET, where both listening for incoming traffic is much easier, and writing a service - even in (gasp) VB - is possible and, dare I say, easy.

    3: Take a look at Julian Templeman's book on Beginning Windows NT Programming - http://www.amazon.com/exec/obidos/tg/detail/-/1861000170/104-9056397-1831954 - it's a bit of an antique today, and is only available used, but the book will help you do what you want.

    HTH.
  • Anonymous
    September 29, 2005
    Take a look at: http://www.codeproject.com/Purgatory/winservicehost.asp

    The display is pretty hosed up, but it should give you a basic idea of how to host your remoting objects.

    To create a windows service you should derive from ServiceBase. The article above shows how to do this as well.

    Enjoy!
  • Anonymous
    September 30, 2005
    The comment has been removed
  • Anonymous
    September 30, 2005
    Oh Yeah and I also recomend another trick I have done as well. Basically make the service itself very slim. What you have the service do is load up another dll in a new app domain created dynamically. The DLL is what does the work. This way if the application crashes or something you can detect this in the service, dump the app domain, and the reload it, kind of like restarting an application that crashed. Do all your error logging to the event log. Remember no UI at all in a service, because a service runs with no users ever being logged on.
  • Anonymous
    September 30, 2005
    Thanks for all the great suggestions everyone. I am indeed writing it in C#, and I didn't notice when I was creating the project in the first place that I could have just created the it as a new Windows Service project, hehehe. I'll give these suggestions a try.
  • Anonymous
    June 08, 2009
    PingBack from http://insomniacuresite.info/story.php?id=6267