[Tip] Writing a service? Handle OnStart and OnStop asynchronously
[Tip] Writing a service? Handle OnStart and OnStop asynchronously
[Tip] Writing a service? Handle OnStart and OnStop asynchronously
[Tip] Writing a service? Handle OnStart and OnStop asynchronously
[Tip] Writing a service? Handle OnStart and OnStop asynchronously
[Tip] Writing a service? Handle OnStart and OnStop asynchronously [Tip] Writing a service? Handle OnStart and OnStop asynchronously [Tip] Writing a service? Handle OnStart and OnStop asynchronously [Tip] Writing a service? Handle OnStart and OnStop asynchronously [Tip] Writing a service? Handle OnStart and OnStop asynchronously [Tip] Writing a service? Handle OnStart and OnStop asynchronously [Tip] Writing a service? Handle OnStart and OnStop asynchronously [Tip] Writing a service? Handle OnStart and OnStop asynchronously
[Tip] Writing a service? Handle OnStart and OnStop asynchronously [Tip] Writing a service? Handle OnStart and OnStop asynchronously
[Tip] Writing a service? Handle OnStart and OnStop asynchronously
Go Back  Xtreme Visual Basic Talk > > > > [Tip] Writing a service? Handle OnStart and OnStop asynchronously


Reply
 
Thread Tools Display Modes
  #1  
Old 07-29-2004, 09:22 AM
Merrion's Avatar
Merrion[Tip] Writing a service? Handle OnStart and OnStop asynchronously Merrion is offline
Ultimate Contributor

* Guru *
 
Join Date: Sep 2001
Location: Dublin, Ireland
Posts: 1,828
Default [Tip] Writing a service? Handle OnStart and OnStop asynchronously


When you start or stop a service in Windows if the OnStart or OnStop handler doesn't return within 20 seconds the service is marked as not working.

To prevent this do your OnStart or OnStop processing asynchronously....

Code:
Imports System.ServiceProcess

Public Class FunkehMunkehService
    Inherits System.ServiceProcess.ServiceBase

#Region "Asynchronous execution delegates"
    Public Delegate Sub OnStartDelegate()
    Public Delegate Sub OnStopDelegate()
#End Region

#Region "ServiceProcess.ServiceBase overrides"

    Protected Overrides Sub OnStart(ByVal args() As String)
        ' Add code here to start your service. This method should set things
        ' in motion so your service can do its work.
        Dim OnStartDelegateInst As OnStartDelegate = AddressOf OnStartAsynch
        OnStartDelegateInst.BeginInvoke(AddressOf OnStopCallback, OnStartDelegateInst)

    End Sub

    Protected Overrides Sub OnStop()
        ' Add code here to perform any tear-down necessary to stop your service.
        Dim OnStopDelegateInst As OnStopDelegate = AddressOf OnStopAsynch
        OnStopDelegateInst.BeginInvoke(AddressOf OnStopCallback, OnStopDelegateInst)

    End Sub

#End Region

#Region "Asynchronous start/stop handling"
    Private Sub OnStartAsynch()
         '\\ Do the real start code here
    End Sub

    Private Sub OnStopAsynch()
        '\\ Do the real stop code here
    End Sub

    Private Sub OnStartCallback(ByVal ar As IAsyncResult)
        ar.AsyncState.EndInvoke(ar)
    End Sub

    Private Sub OnStopCallback(ByVal ar As IAsyncResult)
        ar.AsyncState.EndInvoke(ar)
    End Sub

#End Region

End Class
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
[Tip] Writing a service? Handle OnStart and OnStop asynchronously
[Tip] Writing a service? Handle OnStart and OnStop asynchronously
[Tip] Writing a service? Handle OnStart and OnStop asynchronously [Tip] Writing a service? Handle OnStart and OnStop asynchronously
[Tip] Writing a service? Handle OnStart and OnStop asynchronously
[Tip] Writing a service? Handle OnStart and OnStop asynchronously
[Tip] Writing a service? Handle OnStart and OnStop asynchronously [Tip] Writing a service? Handle OnStart and OnStop asynchronously [Tip] Writing a service? Handle OnStart and OnStop asynchronously [Tip] Writing a service? Handle OnStart and OnStop asynchronously [Tip] Writing a service? Handle OnStart and OnStop asynchronously [Tip] Writing a service? Handle OnStart and OnStop asynchronously [Tip] Writing a service? Handle OnStart and OnStop asynchronously
[Tip] Writing a service? Handle OnStart and OnStop asynchronously
[Tip] Writing a service? Handle OnStart and OnStop asynchronously
 
[Tip] Writing a service? Handle OnStart and OnStop asynchronously
[Tip] Writing a service? Handle OnStart and OnStop asynchronously
 
-->