Windows Services shutdown order

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill Sonia

    Windows Services shutdown order

    I've written a Windows Service to send e-mails on events like OnStart,
    OnStop, OnShutDown using System.Web.Mail . It works for everything but
    OnShutdown. My guess is that for OnShutDown, once my send mail code is
    executed, other necessary Windows Services have been terminated before
    it can actually send the mail. I've updated my
    HKEY_LOCAL_MACH INE\SYSTEM\Curr entControlSet\S ervices registry
    DependOnService value including SMPTSVC and others. My hope is that the
    services will shut-down in reverse order from start-up; I haven't had
    any luck with this.

    My Questions:
    Do Windows Services (Windows 2000) shutdown in the reverse order from
    which they start-up?

    If so, any idea's as to which service I should include as a dependency?

    If not, is there anyway I can ensure my Windows Service is
    the first to shutdown?

    Thanks,

    ~Bill

    _______________ _________
    Bill Sonia
    Achaia Solutions, Inc


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Richard

    #2
    Windows Services shutdown order

    Hmmm,

    Dunno about shutdown order - last service I wrote was for
    NT 4.0 in C++. Are you sure you're getting notified when
    you shutudown? What does the
    ServiceControll er.CanShutdown property return?

    --Richard

    [color=blue]
    >-----Original Message-----
    >I've written a Windows Service to send e-mails on events[/color]
    like OnStart,[color=blue]
    >OnStop, OnShutDown using System.Web.Mail . It works for[/color]
    everything but[color=blue]
    >OnShutdown. My guess is that for OnShutDown, once my[/color]
    send mail code is[color=blue]
    >executed, other necessary Windows Services have been[/color]
    terminated before[color=blue]
    >it can actually send the mail. I've updated my
    >HKEY_LOCAL_MAC HINE\SYSTEM\Cur rentControlSet\ Services[/color]
    registry[color=blue]
    >DependOnServic e value including SMPTSVC and others. My[/color]
    hope is that the[color=blue]
    >services will shut-down in reverse order from start-up; I[/color]
    haven't had[color=blue]
    >any luck with this.
    >
    >My Questions:
    >Do Windows Services (Windows 2000) shutdown in the[/color]
    reverse order from[color=blue]
    >which they start-up?
    >
    >If so, any idea's as to which service I should include as[/color]
    a dependency?[color=blue]
    >
    >If not, is there anyway I can ensure my Windows Service[/color]
    is[color=blue]
    >the first to shutdown?
    >
    >Thanks,
    >
    >~Bill
    >
    >______________ __________
    >Bill Sonia
    >Achaia Solutions, Inc
    >www.achaiasolutions.com
    >
    >*** Sent via Developersdex http://www.developersdex.com[/color]
    ***[color=blue]
    >Don't just participate in USENET...get rewarded for it!
    >.
    >[/color]

    Comment

    • Jeffrey Tan[MSFT]

      #3
      RE: Windows Services shutdown order


      Hi Bill,

      I think your stmp server is on the same machine as your windows service.
      If you use the smtp server on other machine, all will go well.(I have tried
      this)

      I think you can make 2 service, A depends on B, all write log to the Event
      Log in ShutDown event. Then you can check the log order in the Event Viewer
      if the dependency applies on shutting down.

      Because sending mail through smtp is a long time process, I think even if
      your dependency take effect the sending process may fail.
      So I think you should use the smtp on other machine.

      Hope this helps,

      Best regards,
      Jeffrey Tan
      Microsoft Online Partner Support
      Get Secure! - www.microsoft.com/security
      This posting is provided "as is" with no warranties and confers no rights.

      --------------------
      | From: Bill Sonia <billsonia@acha iasolutions.com >
      | X-Newsreader: AspNNTP 1.50 (ActionJackson. com)
      | Subject: Windows Services shutdown order
      | Mime-Version: 1.0
      | Content-Type: text/plain; charset="us-ascii"
      | Content-Transfer-Encoding: 7bit
      | Message-ID: <OvnSs0ylDHA.16 72@TK2MSFTNGP09 .phx.gbl>
      | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
      | Date: Mon, 20 Oct 2003 10:11:15 -0700
      | NNTP-Posting-Host: actionjackson13 3.dsl.frii.net 216.17.147.133
      | Lines: 1
      | Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP09.phx.g bl
      | Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1926 32
      | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
      |
      | I've written a Windows Service to send e-mails on events like OnStart,
      | OnStop, OnShutDown using System.Web.Mail . It works for everything but
      | OnShutdown. My guess is that for OnShutDown, once my send mail code is
      | executed, other necessary Windows Services have been terminated before
      | it can actually send the mail. I've updated my
      | HKEY_LOCAL_MACH INE\SYSTEM\Curr entControlSet\S ervices registry
      | DependOnService value including SMPTSVC and others. My hope is that the
      | services will shut-down in reverse order from start-up; I haven't had
      | any luck with this.
      |
      | My Questions:
      | Do Windows Services (Windows 2000) shutdown in the reverse order from
      | which they start-up?
      |
      | If so, any idea's as to which service I should include as a dependency?
      |
      | If not, is there anyway I can ensure my Windows Service is
      | the first to shutdown?
      |
      | Thanks,
      |
      | ~Bill
      |
      | _______________ _________
      | Bill Sonia
      | Achaia Solutions, Inc
      | www.achaiasolutions.com
      |
      | *** Sent via Developersdex http://www.developersdex.com ***
      | Don't just participate in USENET...get rewarded for it!
      |

      Comment

      • Bill Sonia

        #4
        RE: Windows Services shutdown order

        My smtp server is on another machine. Can you think of a
        particular service that I should ad a dependecy to?
        [color=blue]
        >-----Original Message-----
        >
        >Hi Bill,
        >
        >I think your stmp server is on the same machine as your[/color]
        windows service.[color=blue]
        >If you use the smtp server on other machine, all will go[/color]
        well.(I have tried[color=blue]
        >this)
        >
        >I think you can make 2 service, A depends on B, all write[/color]
        log to the Event[color=blue]
        >Log in ShutDown event. Then you can check the log order[/color]
        in the Event Viewer[color=blue]
        >if the dependency applies on shutting down.
        >
        >Because sending mail through smtp is a long time process,[/color]
        I think even if[color=blue]
        >your dependency take effect the sending process may fail.
        >So I think you should use the smtp on other machine.
        >
        >Hope this helps,
        >
        >Best regards,
        >Jeffrey Tan
        >Microsoft Online Partner Support
        >Get Secure! - www.microsoft.com/security
        >This posting is provided "as is" with no warranties and[/color]
        confers no rights.[color=blue]
        >
        >--------------------
        >| From: Bill Sonia <billsonia@acha iasolutions.com >
        >| X-Newsreader: AspNNTP 1.50 (ActionJackson. com)
        >| Subject: Windows Services shutdown order
        >| Mime-Version: 1.0
        >| Content-Type: text/plain; charset="us-ascii"
        >| Content-Transfer-Encoding: 7bit
        >| Message-ID: <OvnSs0ylDHA.16 72@TK2MSFTNGP09 .phx.gbl>
        >| Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
        >| Date: Mon, 20 Oct 2003 10:11:15 -0700
        >| NNTP-Posting-Host: actionjackson13 3.dsl.frii.net[/color]
        216.17.147.133[color=blue]
        >| Lines: 1
        >| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl![/color]
        TK2MSFTNGP09.ph x.gbl[color=blue]
        >| Xref: cpmsftngxa06.ph x.gbl[/color]
        microsoft.publi c.dotnet.langua ges.csharp:1926 32[color=blue]
        >| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
        >|
        >| I've written a Windows Service to send e-mails on[/color]
        events like OnStart,[color=blue]
        >| OnStop, OnShutDown using System.Web.Mail . It works for[/color]
        everything but[color=blue]
        >| OnShutdown. My guess is that for OnShutDown, once my[/color]
        send mail code is[color=blue]
        >| executed, other necessary Windows Services have been[/color]
        terminated before[color=blue]
        >| it can actually send the mail. I've updated my
        >| HKEY_LOCAL_MACH INE\SYSTEM\Curr entControlSet\S ervices[/color]
        registry[color=blue]
        >| DependOnService value including SMPTSVC and others. My[/color]
        hope is that the[color=blue]
        >| services will shut-down in reverse order from start-up;[/color]
        I haven't had[color=blue]
        >| any luck with this.
        >|
        >| My Questions:
        >| Do Windows Services (Windows 2000) shutdown in the[/color]
        reverse order from[color=blue]
        >| which they start-up?
        >|
        >| If so, any idea's as to which service I should include[/color]
        as a dependency?[color=blue]
        >|
        >| If not, is there anyway I can ensure my Windows Service[/color]
        is[color=blue]
        >| the first to shutdown?
        >|
        >| Thanks,
        >|
        >| ~Bill
        >|
        >| _______________ _________
        >| Bill Sonia
        >| Achaia Solutions, Inc
        >| www.achaiasolutions.com
        >|
        >| *** Sent via Developersdex http://www.developersdex.com[/color]
        ***[color=blue]
        >| Don't just participate in USENET...get rewarded for it!
        >|
        >
        >.
        >[/color]

        Comment

        • Jeffrey Tan[MSFT]

          #5
          RE: Windows Services shutdown order


          Hi Bill,

          I have tried to send mail in Shutdown event, it works well, and my smtp
          server is not on the same machine with the application.
          As you said your smtp server is no another machine, I think you should not
          get any trouble of sending mail in shutdown event.

          I think you can create a tmp file on disk in shutdown event, then you can
          affirm your shutdown event is called corrently.
          Something like this:
          protected override void OnShutdown()
          {
          FileStream f=File.Create(" D:\\onshutdown. txt");
          base.OnShutdown ();
          }

          Best regards,
          Jeffrey Tan
          Microsoft Online Partner Support
          Get Secure! - www.microsoft.com/security
          This posting is provided "as is" with no warranties and confers no rights.

          --------------------
          | Content-Class: urn:content-classes:message
          | From: "Bill Sonia" <billsonia@acha iasolutions.com >
          | Sender: "Bill Sonia" <billsonia@acha iasolutions.com >
          | References: <OvnSs0ylDHA.16 72@TK2MSFTNGP09 .phx.gbl>
          <H9tBiR9lDHA.22 00@cpmsftngxa06 .phx.gbl>
          | Subject: RE: Windows Services shutdown order
          | Date: Tue, 21 Oct 2003 07:09:53 -0700
          | Lines: 97
          | Message-ID: <0c1f01c397dc$f fb49590$a301280 a@phx.gbl>
          | MIME-Version: 1.0
          | Content-Type: text/plain;
          | charset="iso-8859-1"
          | Content-Transfer-Encoding: 7bit
          | X-Newsreader: Microsoft CDO for Windows 2000
          | X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
          | Thread-Index: AcOX3P+0rz/7d7qaRr6m4jMwxG y8Ng==
          | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
          | Path: cpmsftngxa06.ph x.gbl
          | Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1928 76
          | NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
          | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
          |
          | My smtp server is on another machine. Can you think of a
          | particular service that I should ad a dependecy to?
          |
          | >-----Original Message-----
          | >
          | >Hi Bill,
          | >
          | >I think your stmp server is on the same machine as your
          | windows service.
          | >If you use the smtp server on other machine, all will go
          | well.(I have tried
          | >this)
          | >
          | >I think you can make 2 service, A depends on B, all write
          | log to the Event
          | >Log in ShutDown event. Then you can check the log order
          | in the Event Viewer
          | >if the dependency applies on shutting down.
          | >
          | >Because sending mail through smtp is a long time process,
          | I think even if
          | >your dependency take effect the sending process may fail.
          | >So I think you should use the smtp on other machine.
          | >
          | >Hope this helps,
          | >
          | >Best regards,
          | >Jeffrey Tan
          | >Microsoft Online Partner Support
          | >Get Secure! - www.microsoft.com/security
          | >This posting is provided "as is" with no warranties and
          | confers no rights.
          | >
          | >--------------------
          | >| From: Bill Sonia <billsonia@acha iasolutions.com >
          | >| X-Newsreader: AspNNTP 1.50 (ActionJackson. com)
          | >| Subject: Windows Services shutdown order
          | >| Mime-Version: 1.0
          | >| Content-Type: text/plain; charset="us-ascii"
          | >| Content-Transfer-Encoding: 7bit
          | >| Message-ID: <OvnSs0ylDHA.16 72@TK2MSFTNGP09 .phx.gbl>
          | >| Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
          | >| Date: Mon, 20 Oct 2003 10:11:15 -0700
          | >| NNTP-Posting-Host: actionjackson13 3.dsl.frii.net
          | 216.17.147.133
          | >| Lines: 1
          | >| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!
          | TK2MSFTNGP09.ph x.gbl
          | >| Xref: cpmsftngxa06.ph x.gbl
          | microsoft.publi c.dotnet.langua ges.csharp:1926 32
          | >| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
          | >|
          | >| I've written a Windows Service to send e-mails on
          | events like OnStart,
          | >| OnStop, OnShutDown using System.Web.Mail . It works for
          | everything but
          | >| OnShutdown. My guess is that for OnShutDown, once my
          | send mail code is
          | >| executed, other necessary Windows Services have been
          | terminated before
          | >| it can actually send the mail. I've updated my
          | >| HKEY_LOCAL_MACH INE\SYSTEM\Curr entControlSet\S ervices
          | registry
          | >| DependOnService value including SMPTSVC and others. My
          | hope is that the
          | >| services will shut-down in reverse order from start-up;
          | I haven't had
          | >| any luck with this.
          | >|
          | >| My Questions:
          | >| Do Windows Services (Windows 2000) shutdown in the
          | reverse order from
          | >| which they start-up?
          | >|
          | >| If so, any idea's as to which service I should include
          | as a dependency?
          | >|
          | >| If not, is there anyway I can ensure my Windows Service
          | is
          | >| the first to shutdown?
          | >|
          | >| Thanks,
          | >|
          | >| ~Bill
          | >|
          | >| _______________ _________
          | >| Bill Sonia
          | >| Achaia Solutions, Inc
          | >| www.achaiasolutions.com
          | >|
          | >| *** Sent via Developersdex http://www.developersdex.com
          | ***
          | >| Don't just participate in USENET...get rewarded for it!
          | >|
          | >
          | >.
          | >
          |

          Comment

          • Bill

            #6
            RE: Windows Services shutdown order

            Thanks for your help. I'll give that a try

            ~Bill
            [color=blue]
            >-----Original Message-----
            >
            >Hi Bill,
            >
            >I have tried to send mail in Shutdown event, it works[/color]
            well, and my smtp[color=blue]
            >server is not on the same machine with the application.
            >As you said your smtp server is no another machine, I[/color]
            think you should not[color=blue]
            >get any trouble of sending mail in shutdown event.
            >
            >I think you can create a tmp file on disk in shutdown[/color]
            event, then you can[color=blue]
            >affirm your shutdown event is called corrently.
            >Something like this:
            >protected override void OnShutdown()
            >{
            > FileStream f=File.Create(" D:\\onshutdown. txt");
            > base.OnShutdown ();
            >}
            >
            >Best regards,
            >Jeffrey Tan
            >Microsoft Online Partner Support
            >Get Secure! - www.microsoft.com/security
            >This posting is provided "as is" with no warranties and[/color]
            confers no rights.[color=blue]
            >
            >--------------------
            >| Content-Class: urn:content-classes:message
            >| From: "Bill Sonia" <billsonia@acha iasolutions.com >
            >| Sender: "Bill Sonia" <billsonia@acha iasolutions.com >
            >| References: <OvnSs0ylDHA.16 72@TK2MSFTNGP09 .phx.gbl>
            ><H9tBiR9lDHA.2 200@cpmsftngxa0 6.phx.gbl>
            >| Subject: RE: Windows Services shutdown order
            >| Date: Tue, 21 Oct 2003 07:09:53 -0700
            >| Lines: 97
            >| Message-ID: <0c1f01c397dc$f fb49590$a301280 a@phx.gbl>
            >| MIME-Version: 1.0
            >| Content-Type: text/plain;
            >| charset="iso-8859-1"
            >| Content-Transfer-Encoding: 7bit
            >| X-Newsreader: Microsoft CDO for Windows 2000
            >| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
            >| Thread-Index: AcOX3P+0rz/7d7qaRr6m4jMwxG y8Ng==
            >| Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
            >| Path: cpmsftngxa06.ph x.gbl
            >| Xref: cpmsftngxa06.ph x.gbl[/color]
            microsoft.publi c.dotnet.langua ges.csharp:1928 76[color=blue]
            >| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
            >| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
            >|
            >| My smtp server is on another machine. Can you think of[/color]
            a[color=blue]
            >| particular service that I should ad a dependecy to?
            >|
            >| >-----Original Message-----
            >| >
            >| >Hi Bill,
            >| >
            >| >I think your stmp server is on the same machine as[/color]
            your[color=blue]
            >| windows service.
            >| >If you use the smtp server on other machine, all will[/color]
            go[color=blue]
            >| well.(I have tried
            >| >this)
            >| >
            >| >I think you can make 2 service, A depends on B, all[/color]
            write[color=blue]
            >| log to the Event
            >| >Log in ShutDown event. Then you can check the log[/color]
            order[color=blue]
            >| in the Event Viewer
            >| >if the dependency applies on shutting down.
            >| >
            >| >Because sending mail through smtp is a long time[/color]
            process,[color=blue]
            >| I think even if
            >| >your dependency take effect the sending process may[/color]
            fail.[color=blue]
            >| >So I think you should use the smtp on other machine.
            >| >
            >| >Hope this helps,
            >| >
            >| >Best regards,
            >| >Jeffrey Tan
            >| >Microsoft Online Partner Support
            >| >Get Secure! - www.microsoft.com/security
            >| >This posting is provided "as is" with no warranties[/color]
            and[color=blue]
            >| confers no rights.
            >| >
            >| >--------------------
            >| >| From: Bill Sonia <billsonia@acha iasolutions.com >
            >| >| X-Newsreader: AspNNTP 1.50 (ActionJackson. com)
            >| >| Subject: Windows Services shutdown order
            >| >| Mime-Version: 1.0
            >| >| Content-Type: text/plain; charset="us-ascii"
            >| >| Content-Transfer-Encoding: 7bit
            >| >| Message-ID: <OvnSs0ylDHA.16 72@TK2MSFTNGP09 .phx.gbl>
            >| >| Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
            >| >| Date: Mon, 20 Oct 2003 10:11:15 -0700
            >| >| NNTP-Posting-Host: actionjackson13 3.dsl.frii.net
            >| 216.17.147.133
            >| >| Lines: 1
            >| >| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!
            >| TK2MSFTNGP09.ph x.gbl
            >| >| Xref: cpmsftngxa06.ph x.gbl
            >| microsoft.publi c.dotnet.langua ges.csharp:1926 32
            >| >| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
            >| >|
            >| >| I've written a Windows Service to send e-mails on
            >| events like OnStart,
            >| >| OnStop, OnShutDown using System.Web.Mail . It works[/color]
            for[color=blue]
            >| everything but
            >| >| OnShutdown. My guess is that for OnShutDown, once[/color]
            my[color=blue]
            >| send mail code is
            >| >| executed, other necessary Windows Services have been
            >| terminated before
            >| >| it can actually send the mail. I've updated my
            >| >| HKEY_LOCAL_MACH INE\SYSTEM\Curr entControlSet\S ervices
            >| registry
            >| >| DependOnService value including SMPTSVC and others.[/color]
            My[color=blue]
            >| hope is that the
            >| >| services will shut-down in reverse order from start-[/color]
            up;[color=blue]
            >| I haven't had
            >| >| any luck with this.
            >| >|
            >| >| My Questions:
            >| >| Do Windows Services (Windows 2000) shutdown in the
            >| reverse order from
            >| >| which they start-up?
            >| >|
            >| >| If so, any idea's as to which service I should[/color]
            include[color=blue]
            >| as a dependency?
            >| >|
            >| >| If not, is there anyway I can ensure my Windows[/color]
            Service[color=blue]
            >| is
            >| >| the first to shutdown?
            >| >|
            >| >| Thanks,
            >| >|
            >| >| ~Bill
            >| >|
            >| >| _______________ _________
            >| >| Bill Sonia
            >| >| Achaia Solutions, Inc
            >| >| www.achaiasolutions.com
            >| >|
            >| >| *** Sent via Developersdex[/color]
            http://www.developersdex.com[color=blue]
            >| ***
            >| >| Don't just participate in USENET...get rewarded for[/color]
            it![color=blue]
            >| >|
            >| >
            >| >.
            >| >
            >|
            >
            >.
            >[/color]

            Comment

            • Jeffrey Tan[MSFT]

              #7
              RE: Windows Services shutdown order


              Hi Bill,

              Is your problem resolved?
              If you have any question, please feel free to let me know.

              Best regards,
              Jeffrey Tan
              Microsoft Online Partner Support
              Get Secure! - www.microsoft.com/security
              This posting is provided "as is" with no warranties and confers no rights.

              --------------------
              | Content-Class: urn:content-classes:message
              | From: "Bill" <anonymous@disc ussions.microso ft.com>
              | Sender: "Bill" <anonymous@disc ussions.microso ft.com>
              | References: <OvnSs0ylDHA.16 72@TK2MSFTNGP09 .phx.gbl>
              <H9tBiR9lDHA.22 00@cpmsftngxa06 .phx.gbl>
              <0c1f01c397dc$f fb49590$a301280 a@phx.gbl>
              <K3VtLGGmDHA.22 00@cpmsftngxa06 .phx.gbl>
              | Subject: RE: Windows Services shutdown order
              | Date: Wed, 22 Oct 2003 06:22:44 -0700
              | Lines: 173
              | Message-ID: <05e701c3989f$9 3bc5080$a001280 a@phx.gbl>
              | MIME-Version: 1.0
              | Content-Type: text/plain;
              | charset="iso-8859-1"
              | Content-Transfer-Encoding: 7bit
              | X-Newsreader: Microsoft CDO for Windows 2000
              | X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
              | Thread-Index: AcOYn5O5V0KNMcT 2QbWI+w2WP032tw ==
              | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
              | Path: cpmsftngxa06.ph x.gbl
              | Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1931 56
              | NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
              | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
              |
              | Thanks for your help. I'll give that a try
              |
              | ~Bill
              |
              | >-----Original Message-----
              | >
              | >Hi Bill,
              | >
              | >I have tried to send mail in Shutdown event, it works
              | well, and my smtp
              | >server is not on the same machine with the application.
              | >As you said your smtp server is no another machine, I
              | think you should not
              | >get any trouble of sending mail in shutdown event.
              | >
              | >I think you can create a tmp file on disk in shutdown
              | event, then you can
              | >affirm your shutdown event is called corrently.
              | >Something like this:
              | >protected override void OnShutdown()
              | >{
              | > FileStream f=File.Create(" D:\\onshutdown. txt");
              | > base.OnShutdown ();
              | >}
              | >
              | >Best regards,
              | >Jeffrey Tan
              | >Microsoft Online Partner Support
              | >Get Secure! - www.microsoft.com/security
              | >This posting is provided "as is" with no warranties and
              | confers no rights.
              | >
              | >--------------------
              | >| Content-Class: urn:content-classes:message
              | >| From: "Bill Sonia" <billsonia@acha iasolutions.com >
              | >| Sender: "Bill Sonia" <billsonia@acha iasolutions.com >
              | >| References: <OvnSs0ylDHA.16 72@TK2MSFTNGP09 .phx.gbl>
              | ><H9tBiR9lDHA.2 200@cpmsftngxa0 6.phx.gbl>
              | >| Subject: RE: Windows Services shutdown order
              | >| Date: Tue, 21 Oct 2003 07:09:53 -0700
              | >| Lines: 97
              | >| Message-ID: <0c1f01c397dc$f fb49590$a301280 a@phx.gbl>
              | >| MIME-Version: 1.0
              | >| Content-Type: text/plain;
              | >| charset="iso-8859-1"
              | >| Content-Transfer-Encoding: 7bit
              | >| X-Newsreader: Microsoft CDO for Windows 2000
              | >| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
              | >| Thread-Index: AcOX3P+0rz/7d7qaRr6m4jMwxG y8Ng==
              | >| Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
              | >| Path: cpmsftngxa06.ph x.gbl
              | >| Xref: cpmsftngxa06.ph x.gbl
              | microsoft.publi c.dotnet.langua ges.csharp:1928 76
              | >| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
              | >| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
              | >|
              | >| My smtp server is on another machine. Can you think of
              | a
              | >| particular service that I should ad a dependecy to?
              | >|
              | >| >-----Original Message-----
              | >| >
              | >| >Hi Bill,
              | >| >
              | >| >I think your stmp server is on the same machine as
              | your
              | >| windows service.
              | >| >If you use the smtp server on other machine, all will
              | go
              | >| well.(I have tried
              | >| >this)
              | >| >
              | >| >I think you can make 2 service, A depends on B, all
              | write
              | >| log to the Event
              | >| >Log in ShutDown event. Then you can check the log
              | order
              | >| in the Event Viewer
              | >| >if the dependency applies on shutting down.
              | >| >
              | >| >Because sending mail through smtp is a long time
              | process,
              | >| I think even if
              | >| >your dependency take effect the sending process may
              | fail.
              | >| >So I think you should use the smtp on other machine.
              | >| >
              | >| >Hope this helps,
              | >| >
              | >| >Best regards,
              | >| >Jeffrey Tan
              | >| >Microsoft Online Partner Support
              | >| >Get Secure! - www.microsoft.com/security
              | >| >This posting is provided "as is" with no warranties
              | and
              | >| confers no rights.
              | >| >
              | >| >--------------------
              | >| >| From: Bill Sonia <billsonia@acha iasolutions.com >
              | >| >| X-Newsreader: AspNNTP 1.50 (ActionJackson. com)
              | >| >| Subject: Windows Services shutdown order
              | >| >| Mime-Version: 1.0
              | >| >| Content-Type: text/plain; charset="us-ascii"
              | >| >| Content-Transfer-Encoding: 7bit
              | >| >| Message-ID: <OvnSs0ylDHA.16 72@TK2MSFTNGP09 .phx.gbl>
              | >| >| Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
              | >| >| Date: Mon, 20 Oct 2003 10:11:15 -0700
              | >| >| NNTP-Posting-Host: actionjackson13 3.dsl.frii.net
              | >| 216.17.147.133
              | >| >| Lines: 1
              | >| >| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!
              | >| TK2MSFTNGP09.ph x.gbl
              | >| >| Xref: cpmsftngxa06.ph x.gbl
              | >| microsoft.publi c.dotnet.langua ges.csharp:1926 32
              | >| >| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
              | >| >|
              | >| >| I've written a Windows Service to send e-mails on
              | >| events like OnStart,
              | >| >| OnStop, OnShutDown using System.Web.Mail . It works
              | for
              | >| everything but
              | >| >| OnShutdown. My guess is that for OnShutDown, once
              | my
              | >| send mail code is
              | >| >| executed, other necessary Windows Services have been
              | >| terminated before
              | >| >| it can actually send the mail. I've updated my
              | >| >| HKEY_LOCAL_MACH INE\SYSTEM\Curr entControlSet\S ervices
              | >| registry
              | >| >| DependOnService value including SMPTSVC and others.
              | My
              | >| hope is that the
              | >| >| services will shut-down in reverse order from start-
              | up;
              | >| I haven't had
              | >| >| any luck with this.
              | >| >|
              | >| >| My Questions:
              | >| >| Do Windows Services (Windows 2000) shutdown in the
              | >| reverse order from
              | >| >| which they start-up?
              | >| >|
              | >| >| If so, any idea's as to which service I should
              | include
              | >| as a dependency?
              | >| >|
              | >| >| If not, is there anyway I can ensure my Windows
              | Service
              | >| is
              | >| >| the first to shutdown?
              | >| >|
              | >| >| Thanks,
              | >| >|
              | >| >| ~Bill
              | >| >|
              | >| >| _______________ _________
              | >| >| Bill Sonia
              | >| >| Achaia Solutions, Inc
              | >| >| www.achaiasolutions.com
              | >| >|
              | >| >| *** Sent via Developersdex
              | http://www.developersdex.com
              | >| ***
              | >| >| Don't just participate in USENET...get rewarded for
              | it!
              | >| >|
              | >| >
              | >| >.
              | >| >
              | >|
              | >
              | >.
              | >
              |

              Comment

              • Bill Sonia

                #8
                RE: Windows Services shutdown order

                Thanks for your interest. As it turns out I was headed down the wrong
                road. My process does 2 things, first it writes to the event log and
                second it sends the e-mail. Once I added a try catch around each
                portion, it did send the mail.

                i.e.
                public void HandleEvent()
                {
                try
                {
                EventLog.WriteE ntry(,,,)
                }
                catch { }

                try
                {
                //My send mail routine
                mySmtp.SendMail ()
                }
                catch { }
                }

                The EventLog.WriteE ntry worked onStart, onStop, onPause, etc... but
                would error onShutDown. Once that was handled, the mail worked. I can
                and will live without the event log on shut down but ideally I would
                would like to get my app to write to the event log before the system
                shuts down. Sql Server does it.

                Thanks again for your help.

                _______________ _________
                Bill Sonia
                Achaia Solutions, Inc


                *** Sent via Developersdex http://www.developersdex.com ***
                Don't just participate in USENET...get rewarded for it!

                Comment

                • Jeffrey Tan[MSFT]

                  #9
                  RE: Windows Services shutdown order


                  Hi Bill,

                  Thanks for your feedback.
                  I am glad your program finally works. I can reproduce your eventlog
                  problem, it is because the eventlog service was shutdown before your
                  windows service.
                  I have tried to set our windows service depend on the eventlog service, but
                  always generates error. May be you can try to set the dependency in your
                  machine.

                  Hope this helps,

                  Best regards,
                  Jeffrey Tan
                  Microsoft Online Partner Support
                  Get Secure! - www.microsoft.com/security
                  This posting is provided "as is" with no warranties and confers no rights.

                  --------------------
                  | From: Bill Sonia <billsonia@acha iasolutions.com >
                  | References: <hAUUKTsoDHA.18 04@cpmsftngxa06 .phx.gbl>
                  | X-Newsreader: AspNNTP 1.50 (ActionJackson. com)
                  | Subject: RE: Windows Services shutdown order
                  | Mime-Version: 1.0
                  | Content-Type: text/plain; charset="us-ascii"
                  | Content-Transfer-Encoding: 7bit
                  | Message-ID: <eRCrMbuoDHA.16 76@TK2MSFTNGP09 .phx.gbl>
                  | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
                  | Date: Tue, 04 Nov 2003 07:17:43 -0800
                  | NNTP-Posting-Host: actionjackson13 3.dsl.frii.net 216.17.147.133
                  | Lines: 1
                  | Path:
                  cpmsftngxa06.ph x.gbl!cpmsftngx a09.phx.gbl!cpm sftngxa10.phx.g bl!TK2MSFTNGXA0 5
                  phx.gbl!TK2MSFT NGP08.phx.gbl!T K2MSFTNGP09.phx .gbl
                  | Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1966 08
                  | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
                  |
                  | Thanks for your interest. As it turns out I was headed down the wrong
                  | road. My process does 2 things, first it writes to the event log and
                  | second it sends the e-mail. Once I added a try catch around each
                  | portion, it did send the mail.
                  |
                  | i.e.
                  | public void HandleEvent()
                  | {
                  | try
                  | {
                  | EventLog.WriteE ntry(,,,)
                  | }
                  | catch { }
                  |
                  | try
                  | {
                  | //My send mail routine
                  | mySmtp.SendMail ()
                  | }
                  | catch { }
                  | }
                  |
                  | The EventLog.WriteE ntry worked onStart, onStop, onPause, etc... but
                  | would error onShutDown. Once that was handled, the mail worked. I can
                  | and will live without the event log on shut down but ideally I would
                  | would like to get my app to write to the event log before the system
                  | shuts down. Sql Server does it.
                  |
                  | Thanks again for your help.
                  |
                  | _______________ _________
                  | Bill Sonia
                  | Achaia Solutions, Inc
                  | www.achaiasolutions.com
                  |
                  | *** Sent via Developersdex http://www.developersdex.com ***
                  | Don't just participate in USENET...get rewarded for it!
                  |

                  Comment

                  Working...