VB.Net
  Home arrow VB.Net arrow Page 2 - Creating A Windows Service in VB.NET
IBM Rational Software Development Conference
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Download TestComplete 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VB.NET

Creating A Windows Service in VB.NET
By: Jayesh Jain
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 218
    2002-10-04

    Table of Contents:
  • Creating A Windows Service in VB.NET
  • What is Windows Service
  • Adding an Installer to the Project
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Creating A Windows Service in VB.NET - What is Windows Service
    (Page 2 of 4 )

    Previously called an NT service, the core function of a Windows aervice is to run an application in the background. There are few things that make them different from a Windows application. A Windows service starts much before any user logs in to the system (if it has been setup to start at boot up process). A Windows service can also be setup in such a way that it requires a user to start it manually – the ultimate customization!

    Windows services have their own processes, and hence run very efficiently. Normally a Windows service will not have a user interface for the simple reason that it can be run even if no one is logged into the system, but this is not a rule -- you can still have a Windows service with a user interface.

    In windows 2000 you can view a list of services currently running on your computer by opening Control Panel -> Administrative Tools -> Services, as shown below:

    The services running on my PC

    Creating A Windows Service in VB.NET
    Prior to VB.NET, creating a Windows service was a lot of work, and was left to the C++ guru's, as you had to use some system level procedures, which were extremely difficult. Thanks to VB.NET, however, this is becoming very easy and we shall now learn how to create a Windows Service in VB.Net.

    There are a few things that you should know before we dive in, however. Windows services are not available under Windows 95, 98 or ME -- you need to have Windows NT or Windows 2000 to run services.

    The advantage to use .NET is that the framework incorporates all of the classes, which shall help us to create, install and control a Windows Service. Open Visual Studio .NET and create a new Windows service project, which we shall call "MyService". Click OK.

    Creating our Windows service

    Add a timer control from the toolbar in the Components tab. In the properties window of Timer1, change the interval property to 10000, which is 10 seconds.

    Examining The Source Code
    Double click the timer1 control to open up the code window for Timer1_Elapsed. Type in the following code:

    Dim MyLog As New EventLog() ' create a new event log
    ' Check if the the Event Log Exists
    If Not MyLog.SourceExists("MyService") Then
    MyLog.CreateEventSource("MyService", "Myservice Log") ' Create Log
    End If
    MyLog.Source = "MyService"
    ' Write to the Log
    MyLog.WriteEntry("MyService Log", "This is log on " & _
    CStr(TimeOfDay), EventLogEntryType.Information)


    Type in the following code for the OnStart procedure:

    Timer1.Enabled = True

    Type in the following code in the OnStop procedure:

    Timer1.Enabled = False

    Our application is now ready, but there are a few things that we need to do before we move ahead when we build this application. The executable created is not a Windows application, and hence you can't just click and run it -- it needs to be installed as a service, but don't worry, we don't have to do it manually -- VB.Net has a facility where we can add an installer to our program and then use a utility to install the service.

    More VB.Net Articles
    More By Jayesh Jain


     

    VB.NET ARTICLES

    - MyClass - Implementing Polymorphism in VB.Net
    - Building a News Ticker Using VB.Net
    - Everything You Wanted to Know About Forms In...
    - Building Assemblies with VB.Net
    - Simple VB.NET Notify Icon with Panel Applica...
    - Regular Expressions in .NET
    - String Encryption With Visual Basic .NET
    - Deploying Applications in VB.NET: Part 1/2
    - Watching Folder Activity in VB.NET
    - Creating A Windows Service in VB.NET
    - Implementing The Google Web Service In VB.NET
    - Migrating to Visual Basic.NET from Visual Ba...


     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway