Results 1 to 9 of 9

Thread: Way to have a service restart itself?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Way to have a service restart itself?

    Is there a way to program a service to restart itself? I am talking to some third party hardware/software, and if a connection gets lost, the software doesn't want to reset itself correctly unless a shut down and restart the service completely. Basically I want to test for a valid binding, and if it has failed, do a self restart. Is it possible, or do I have to write a second service that looks for some kind of flag and resets the first service if it finds it? Thanks.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Way to have a service restart itself?

    I know services have built in fault recovery if that is what you mean.

    When you go into services.msc, open up any services properties, and go to the recovery tab for the available options. You may be able to use this to meet your needs?

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Re: Way to have a service restart itself?

    Quote Originally Posted by kleinma
    I know services have built in fault recovery if that is what you mean.

    When you go into services.msc, open up any services properties, and go to the recovery tab for the available options. You may be able to use this to meet your needs?
    Hmmm...anybody know how to tell a service it is in fault? Will an uncaught exception do it?
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  4. #4
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Way to have a service restart itself?

    Quote Originally Posted by SeanGrebey
    Is there a way to program a service to restart itself? I am talking to some third party hardware/software, and if a connection gets lost, the software doesn't want to reset itself correctly unless a shut down and restart the service completely. Basically I want to test for a valid binding, and if it has failed, do a self restart. Is it possible, or do I have to write a second service that looks for some kind of flag and resets the first service if it finds it? Thanks.
    It sounds like you have a bad design and shouldn't be resolved by trying to just restart itself.

    Why couldn't you handle this yourself in your service? If your service loses the connection then why can't the service just reconnect? Just restarting it isn't a very good solution.
    Quote Originally Posted by SeanGrebey
    Hmmm...anybody know how to tell a service it is in fault? Will an uncaught exception do it?
    The service kind of won't work if it's faulting... at least I believe that's how it works.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Way to have a service restart itself?

    I agree that unless it is a really poorly made 3rd party thing you are working with, there should be some way in your code to restart the connection without needing to restart the service. You may be just be going about this the wrong way.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Re: Way to have a service restart itself?

    Quote Originally Posted by kasracer
    It sounds like you have a bad design and shouldn't be resolved by trying to just restart itself.

    Why couldn't you handle this yourself in your service? If your service loses the connection then why can't the service just reconnect? Just restarting it isn't a very good solution.
    The service kind of won't work if it's faulting... at least I believe that's how it works.
    I didn't write the 3rd party library, I don't know what is going on behind the scenes, I don't know why it isn't releasing correctly, but once you have created a connection and it fails, it won't successfully create another one until the service has been restarted. It is not a particularly good solution to restart the service, but I don't have a lot of options at this point. There aren't any reconnects in their library. All I can do is destroy their objects and recreate them, but that doesn't work. They won't reconnect once they are recreated. I am open to any better ideas, but until then I have a deadline and this will resolve it.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  7. #7
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Way to have a service restart itself?

    If you can post some code where you try to do your destroy/recreate, then maybe something will stick out... but short of that, I don't really have any suggestions other than contacting the people who made the component you are interfacing with.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Re: Way to have a service restart itself?

    Quote Originally Posted by kleinma
    I agree that unless it is a really poorly made 3rd party thing you are working with, there should be some way in your code to restart the connection without needing to restart the service. You may be just be going about this the wrong way.
    I believe I am the first developer to use it...
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Re: Way to have a service restart itself?

    Quote Originally Posted by kleinma
    If you can post some code where you try to do your destroy/recreate, then maybe something will stick out... but short of that, I don't really have any suggestions other than contacting the people who made the component you are interfacing with.
    Yeah I have an e-mail in to three of their developers right now asking them what steps I need to follow to recreate a connection. They usually answer pretty quickly, but it has been almost a day now, so I am getting a creeping suspicion they aren't entirely sure.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width