Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Window Service

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 182
    Comment on it

    "Window Service: An Overview"

    What is a Window Service ?
        Windows service is a computer program that operates in the background and does not have any interface to the user.It helps to create a long-running executable applications which has the ability to start automatically or manualy when the computer boots and also can be paused, stopped and restarted.

    Getting Started:

    Let us discuss the steps involved in creating a windows service application:-

    Step 1: Open Visual Studio, Select Windows Desktop under Visual C# option. On the right side select Windows
                    Service and save the application.

    Step 2: After clicking Ok a screen appears with an option "click here to switch to code view", click on this option,
                    this will open the code view of the application.

    Example:-

    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.Tasks;
    
    
    namespace BlogService
    {
        public partial class Service1 : ServiceBase
        {
            public Service1()
            {
                InitializeComponent();
            }
    
            protected override void OnStart(string[] args)
            {
    
            }
    
            protected override void OnStop()        
            {
    
            }
        }
    }
    

      The OnStart() method triggers when the Windows Service starts and the OnStop() method triggers when the service stops.So if we want any activity to be performed on start of the windows service we can write it under OnStart(), Similarly if we want any activity to be performed when the windows service is stopped, we can write it under OnStop().

    Step 3: Now add a class to the project to perform operations as required.

    Step 4: Now return to the Windows service [Design] and right-click on the editor window then click "Add Installer".

    Step 5: This will add a ProjectInstaller.cs to the solution and a serviceinstaller will appear in the design view.

    Step 6: Right Click on the serviceinstaller and select the properties, here we can change
                    the ServiceName, change the Start type to Manual or Automatic,etc.

    Step 7: Now go to the location where you have saved the Window Service, go to the service.exe file inside the bin
                    folder and copy the path.

    Step 8: Open Developers Command Prompt in administrator mode, and type the following to install    the window
                    service:
                   cd "full path to the Service.exe"
                   then write-
                   installutil "Name of the Service.exe"
                  This will successfully install the service.

    Step 9: To start the service manually run the command services.msc , this will display all the services,now u can
                      start after selecting your service.

    Step 10: To stop the service click on stop and to uninstall type the following command on the Developer's
                        command prompt:
                    installutil /u "Service Name.exe"

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: