ComponentSpace Professional .NET and ActiveX components for developers
ComponentSpace Home | Products | Downloads | Support | Purchase | Services | About Us
 

Code Samples

The product includes numerous Visual Basic sample applications. All samples include complete source code. For more detailed sample code please refer to the sample applications.


Windows Service in Visual Basic

Listing 1 shows a very simple, but complete, Windows service written in Visual Basic.



' Must implement IService to be hosted as a service
Implements IService

Private Property Get IService_Pausable() As Boolean
    ' Only support pause/continue if it makes sense
    IService_Pausable = True
End Property

Private Sub IService_OnStart(ByVal Arguments As Variant)
    App.LogEvent "Example Service starting with arguments <" & Arguments & ">", _
                 vbLogEventTypeInformation
    
    ' Do whatever is required to start the service
    ' but return as quickly as possible
End Sub

Private Sub IService_OnStop()
    App.LogEvent "Example Service stopping", vbLogEventTypeInformation
    
    ' Do whatever is required to stop the service
    ' but return as quickly as possible
End Sub

Private Sub IService_OnPause()
    ' Will only be called if pausable
    App.LogEvent "Example Service pausing", vbLogEventTypeInformation
End Sub

Private Sub IService_OnContinue()
    ' Will only be called if pausable
    App.LogEvent "Example Service continuing", vbLogEventTypeInformation
End Sub

Private Sub IService_OnControl(ByVal OpCode As Long)
    ' Handle service specific controls
    App.LogEvent "Example Service received control " & OpCode, _
                 vbLogEventTypeInformation
End Sub

Private Sub IService_OnShutdown()
    ' Perform any shutdown specific processing
    App.LogEvent "Example Service shutting down", vbLogEventTypeInformation
End Sub
									

Listing 1 Windows Service in Visual Basic