Click here to Skip to main content
14,145,240 members
Click here to Skip to main content
Add your own
alternative version


80 bookmarked
Posted 5 May 2005

Scheduling tasks with VB.NET as Windows services

, 5 May 2005
Rate this:
Please Sign up or sign in to vote.
An article on Windows services using VB.NET.


After the introduction of .NET, writing services using VB.NET has become very simple and easy. But still beginners need a start from somewhere to know how to achieve this. Attached is a sample application which demonstrates this concept.


This is a slightly modified version of the article submitted by Xiangyang Liu, to create a simple Windows service using VB.NET. Thanks to Xiangyang Liu, for the code that I have used to build Windows services in .NET. This code explains some additional things like, XML file reading, database and stored procedure handling etc.. I have simplified the code to make it simple to understand for the beginners.

Using the code

For those who know a bit of .NET applications, this code is pretty simple. To install and test this application, please modify the application path within the Installservice.bat which exists in the bin folder.

serviceInstaller -i NotificationService 
ServiceInstaller -r NotificationService

If the path is correct in the installservice.bat, then the new service called NotificationService will be installed and started within the Service Control Manager.

The class NotificationService is inherited from System.ServiceProcess.ServiceBase. It will run the code only once, when the user logs in for the first time or when the service is started. But if you want the action to keep happening depending upon a trigger you need to use the timer calls from the system. Please also note that, the Timer event calls the subroutine which sends an email. I have set it to fire the event every two seconds. You can change this if you want to. I have used my personal email ID here. Please change it before you test the code or I will be getting millions of emails.

Protected Overrides Sub OnStart(ByVal args() As String)
            t = New Timer(2000)
            AddHandler t.Elapsed, AddressOf TimerFired
            With t
                .AutoReset = True
                .Enabled = True
            End With
        Catch obug As Exception
            Throw obug
        End Try
    End Sub

 Protected Overrides Sub OnStop()
  log.WriteEntry("Service Stopping", EventLogEntryType.Information)
  Catch obug As Exception
  End Try
  End Sub

Private Sub TimerFired(ByVal sender As Object, ByVal e As ElapsedEventArgs)
End Sub


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
China China
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralGood article Pin
Fernando Tripaldi7-Nov-10 3:07
memberFernando Tripaldi7-Nov-10 3:07 
Questionwindow service Pin
kk_upadhyay22-Jul-07 21:57
memberkk_upadhyay22-Jul-07 21:57 
GeneralGreat Article Pin
Member 372783721-Mar-07 10:41
memberMember 372783721-Mar-07 10:41 
Generaleasy to implement Pin
bayla13-Nov-06 7:54
memberbayla13-Nov-06 7:54 
Generalstruggling with remoting of a form Pin
dpietro23-May-06 6:31
memberdpietro23-May-06 6:31 
Generaluser interface in windows service Pin
Sebastián Vázquez19-Apr-06 7:19
memberSebastián Vázquez19-Apr-06 7:19 
GeneralRe: user interface in windows service Pin
Jonathan [Darka]19-Apr-06 7:38
mentorJonathan [Darka]19-Apr-06 7:38 
GeneralIntegrate window service with any web application Pin
Faheem Habib25-Aug-05 1:37
memberFaheem Habib25-Aug-05 1:37 
GeneralRe: Integrate window service with any web application Pin
DigiOz Multimedia25-Aug-07 12:41
memberDigiOz Multimedia25-Aug-07 12:41 
Questionc# implementation? Pin
Huisheng Chen5-May-05 4:22
memberHuisheng Chen5-May-05 4:22 
AnswerRe: c# implementation? Pin
Member 10003095-May-05 4:26
memberMember 10003095-May-05 4:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.190518.1 | Last Updated 5 May 2005
Article Copyright 2005 by shan
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid