* IBM to offer mobile security as a service IBM will start delivering mobile security-as-a-service (MaaS) through its own cloud infrastructure in India, a move that is expected to better address in-country data requirements... IBM Spectrum Computing: IBM has enlarged its portfolio of software-defined infrastructure solutions with cognitive features for workload management.  * LiFi internet technology has been introduced, the new type of wireless internet connection that gives 100 times faster than traditional WiFi -- Invented by Professor Harald Haas from the University of Edinburgh. * Sci. Rachid Yazami has developed a smart chip that charges smartphones in less than 10 minutes. BenQ has launched BlueCore projector - Consumer electronics major BenQ has launched its first BlueCore laser light source projector. For those unaware, devices with BlueCore laser technology have a high contrast output of 80000:1 with an extended lamp life and efficiency. *** 
  May 30 2015 1:04PM     John
  0 Comments    8957 Views  
In this article John demonstrates, how to Send an Employee Alert Mail for Every Morning Using Windows Service application in C#.
Steps to create Windows service
1. To Create a windows service, open Visual Studio, on the menu bar, choose File, New, Project.

2. In the list of Visual Basic or Visual C# project templates, choose Windows Service, and name the project MyNewService.

3. Choose OK.

4. The project template automatically adds a component class named Service1 that inherits from System.ServiceProcess.ServiceBase.

5.And then right click on Service1.Disigner.cs, click on View Code and paste the following code.
Right click Service1.Disigner.cs and click on View Code .
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace WindowsService1
    public partial class Service1 : ServiceBase
        Thread mainThreadObj;

        DateTime currentDateTime;

        Thread objProcessThread;
        string recievermailid = "xxxxxxx";
        string subject        = "Employee Alert Mail";
        string bodyText       = "This is an Employee Alert Mail.";

        public Service1()

        public void start()

            string[] args = default(string[]);

        protected override void OnStart(string[] args)
            currentDateTime = DateTime.Now;

            mainThreadObj = new Thread(ProcessThread);



        protected override void OnStop()

        private void ProcessThread()
            if (objProcessThread == null ||
            objProcessThread.ThreadState == System.Threading.ThreadState.Stopped ||
            objProcessThread.ThreadState == System.Threading.ThreadState.Unstarted)

                while (DateTime.Now >= currentDateTime.AddHours(12))//Every 12 Hours
                    objProcessThread = new Thread(threadProcessMethod);

                    objProcessThread.IsBackground = true;


                    currentDateTime = currentDateTime.AddSeconds(10);

                    Thread.Sleep( 12 * (60 * (1000 * 60))); //Every 12 Hours


                Thread.Sleep( 12 * (60 * (1000 * 60))); //Every 12 Hours


        private void threadProcessMethod()
        public bool sendmail(string recievermailid, string subject, string bodyText)
            string senderId = "********"// Sender EmailID
            string senderPassword = "*********"// Sender Password

            System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
            mailMessage.From = new MailAddress(senderId);

            mailMessage.Subject = subject;
            mailMessage.SubjectEncoding = System.Text.Encoding.UTF8;

            mailMessage.Body = bodyText;
            mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
            mailMessage.IsBodyHtml = false;

            mailMessage.Priority = MailPriority.High;

            SmtpClient smtpClient = new SmtpClient();
            smtpClient.Credentials = new System.Net.NetworkCredential(senderId, senderPassword);
            smtpClient.Port = 587;
            smtpClient.Host = "";
            smtpClient.EnableSsl = true;

            object userState = mailMessage;

                return true;
            catch (System.Net.Mail.SmtpException)
                return false;
        catch (Exception)
            return false;
Build the windows services, you can find WindowsService1.exe in output console , some thing like this
In the Command Prompt window, navigate to the folder that contains your project's output.
For example, under your
Enter the following command:
installutil.exe WindowsService1.exe
Here you can find more steps to install and uninstall the WindowsService
I hope this page will helps you to send Employee Alert Mail Using window service in C#.Thanks.

Recent Posts
Create Amazon ElasticCache Using Memcached in CSharp
Oct 29 2018 12:09PM Posted By Amose
Get Google Map Lat Lng (Geo Point) By Pincode in C#
Oct 28 2018 12:09PM Posted By Pranav
Google URL Shortener in C#
Oct 20 2018 12:09PM Posted By Sanjay
Bind Gridview from CSV file in Asp.Net C#
Oct 5 2018 12:09PM Posted By Michael
Call WebService method from jQuery in every 1 minute
Sep 26 2018 12:09PM Posted By John
Gridview custom CSS in ASP.Net
Sep 14 2018 12:09PM Posted By Micheal Ryan
Read excel file and bind to Gridview in C#
Sep 10 2018 12:09PM Posted By Micheal
Follow us on Facebook
Follow us on Google +
Recent post in your Email inbox.
Enter your email address: