Here we are going to see how to build a Windows service for fetching records from the database and wishing the person whose birthday falls on that particular day.
The following figure shows the snapshot of the table, which is being used with this application.

The service fetches records for the employee whose birthday falls on a particular day and sends him a birthday wish through the mail.
Note. A little bit lazy to change the name of the service in the attached code. You can give whatever name to the service that suits you.
The default code of Service1.cs added by the Wizard looks like here
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Data.SqlClient;
using System.Web.Mail;
using System.IO;
namespace BirthdayWish
{
public class Service1 : System.ServiceProcess.ServiceBase
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Service1()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent();
// TODO: Add any initialization after the InitComponent call
}
// The main entry point for the process
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
// More than one user Service may run within the same process. To add
// another service to this process, change the following line to
// create a second service object. For example,
//
// ServicesToRun = new System.ServiceProcess.ServiceBase[] {new Service1(), new
// MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service1() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// Service1
//
this.ServiceName = "Service1";
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
/// <summary>
/// Set things in motion so your service can do its work.
/// </summary>
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
}
/// <summary>
/// Stop this service.
/// </summary>
protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service.
}
}
}
Adding functionality to the service.



DarinPosted Dec 14, 2015, 6:16 AM
nyc $hare !!
Anu VPosted Nov 30, 2015, 1:11 AM
good
Rajeesh MenothPosted Aug 11, 2015, 3:03 AM
Good One sir
NARESH BOLUSANIPosted Oct 30, 2013, 1:05 AM
the service1 service on local computer started and then stopped.some services stop automatically if they are not in using by other service or program message is displayed plz how to overcome this message
Mangesh SahooPosted Apr 25, 2012, 8:41 AM
What about the app.config file????
naresh bahekarPosted Aug 9, 2011, 11:19 AM
it is really nice article
kishan gajjarPosted Dec 12, 2010, 1:41 AM
This is great for scheduling process. Try http://quartznet.sourceforge.net
Ravindra DonkadaPosted Oct 31, 2006, 7:30 AM
hello sir, I am Ravindra.Currently doing a project in asp.net and i am writing a windows service for my project .which is similar to the article you submitted. But sir,when I am starting windows service ,i am getting the following message "the service1 service on local computer started and then stopped.some services stop automatically if they have no work to do,for example ,the performance logs and alert service" and I am not getting any email alerts . So, please help.thanks in advance -Ravindra
vasanth kumareditedPosted Feb 28, 2006, 11:48 PMEdited Oct 18, 2006, 1:42 AM
I am vasanth I am new in .net. Is Possible to retrive value from the service. If it is possible,how to retrive values from windowsservice to windowsapplication. reply ur sugession as soon as possible.