* 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    1730 Views  
In this article John demonstrates, how to create a simple Windows Service application in C#, That writes an Eventlog for every 10 Seconds.
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.
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;

        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.AddSeconds(10))//Every 10 Secs
                    objProcessThread = new Thread(threadProcessMethod);

                    objProcessThread.IsBackground = true;


                    currentDateTime = currentDateTime.AddSeconds(10);

                    Thread.Sleep(1000 * 10);


                Thread.Sleep(1000 * 10); //Every 10 Secs


        private void threadProcessMethod()
            Console.WriteLine(" This Method Will Call Every 10 Seconds : " + currentDateTime);
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 steps to install and uninstall the WindowsService
I hope this page will helps you to create first 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: