Click here to Skip to main content
12,630,455 members (33,048 online)
Click here to Skip to main content
Add your own
alternative version


78 bookmarked

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 4:07
memberFernando Tripaldi7-Nov-10 4:07 
Questionwindow service Pin
kk_upadhyay22-Jul-07 22:57
memberkk_upadhyay22-Jul-07 22:57 
GeneralGreat Article Pin
Member #372783721-Mar-07 11:41
memberMember #372783721-Mar-07 11:41 
I have spent a great deal of time to find a starter article for Windows Services.

This is the best article you can find, and I have applied this to my Windows Services Project scheduling a pull from Oracle database into a text file.



Generaleasy to implement Pin
bayla13-Nov-06 8:54
memberbayla13-Nov-06 8:54 
Generalstruggling with remoting of a form Pin
dpietro23-May-06 7:31
memberdpietro23-May-06 7:31 
Generaluser interface in windows service Pin
Sebastián Vázquez19-Apr-06 8:19
memberSebastián Vázquez19-Apr-06 8:19 
GeneralRe: user interface in windows service Pin
Darka19-Apr-06 8:38
memberDarka19-Apr-06 8:38 
GeneralIntegrate window service with any web application Pin
Faheem Habib25-Aug-05 2:37
memberFaheem Habib25-Aug-05 2:37 
GeneralRe: Integrate window service with any web application Pin
DigiOz Multimedia25-Aug-07 13:41
memberDigiOz Multimedia25-Aug-07 13:41 
Questionc# implementation? Pin
Unruled Boy5-May-05 5:22
memberUnruled Boy5-May-05 5:22 
AnswerRe: c# implementation? Pin
Shan Natarajan5-May-05 5:26
memberShan Natarajan5-May-05 5: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.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.161205.3 | Last Updated 5 May 2005
Article Copyright 2005 by shan
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid