News
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
  2 Comments    2061 Views  
In this article John demonstrates, how to create a simple Windows Service application in Visual Studio. Here are the basic steps that you perform to create and use your service:
Creating a Service
1. Create a project by using the Windows Service project template, and configure it. This template creates a class for you that inherits fromSystem.ServiceProcess.ServiceBase and writes much of the basic service code, such as the code to start the service.

2. Write the code for the OnStart and OnStop procedures, and override any other methods that you want to redefine.

3. Implement service pending status . By default, services created with System.ServiceProcess.ServiceBase implement only a subset of the available status flags. If your service takes a long time to start up, pause, or stop, you can implement status values such as Start Pending or Stop Pending to indicate that it's working on an operation.

4. Add the necessary installers for your service application.

5. (Optional) Add startup parameters, specify default startup arguments, and enable users to override default settings when they start your service manually.

6. Build your project .

7. Install your service on the local machine.
8. Access the Windows Service Control Manager and start your service.

9. Uninstall the service .
To begin, you create the project and set values that are required for the service to function correctly.
To create and configure your service
1. In Visual Studio, on the menu bar, choose File, New, Project. The New Project dialog box opens.

2. In the list of Visual Basic or Visual C# project templates, choose Windows Service, and name the project MyNewService. Choose OK. The project template automatically adds a component class named Service1 that inherits from System.ServiceProcess.ServiceBase.

3. On the Edit menu, choose Find and Replace, Find in Files (Keyboard: Ctrl+Shift+F). Change all occurrences of Service1 to MyNewService. You’ll find instances in Service1.cs, Program.cs, and Service1.Designer.cs (or their .vb equivalents).

4. In the Properties window for Service1.cs [Design] or Service1.vb [Design], set the ServiceName and the (Name) property for Service1 toMyNewService, if it's not already set.

5. In Solution Explorer, rename Service1.cs to MyNewService.cs, or Service1.vb to MyNewService.vb.
To install a Windows Service
1. In Windows 7 and Windows Server, open the Developer Command Prompt under Visual Studio Tools in the Start menu. In Windows 8 or Windows 8.1, choose the Visual Studio Tools tile on the Start screen, and then run Developer Command Prompt with administrative credentials. (If you’re using a mouse, right-click on Developer Command Prompt, and then choose Run as Administrator.)

2. In the Command Prompt window, navigate to the folder that contains your project's output. For example, under your My Documents folder, navigate to Visual Studio 2013\Projects\MyNewService\bin\Debug.

3. Enter the following command:
installutil.exe MyNewService.exe
To uninstall your service
1. Open a developer command prompt with administrative credentials.

2. In the Command Prompt window, navigate to the folder that contains your project's output. For example, under your My Documents folder, navigate to Visual Studio 2013\Projects\MyNewService\bin\Debug.

3. Enter the following command:
installutil.exe /u MyNewService.exe
To start and stop your service
1. In Windows, open the Start screen or Start menu, and type services.msc. You should now see MyNewService listed in the Services window.

2. In the Services window, open the shortcut menu for your service, and then choose Start.

3. Open the shortcut menu for the service, and then choose Stop.

4. (Optional) From the command line, you can use the commands net start ServiceName and net stop ServiceName to start and stop your service.
I hope this page will helps you to create first window service in C#.Thanks.
BackToTop
Comments


AnonymousUser
Nov 4 2015 10:15PM
Shall I install .exe file directly by double clicking of .exe ???
Vishwanath
Nov 5 2015 4:46AM
Yes, You are correct. You can also double click the application file (.exe) to install the windows service.
Then open IIS manager from run command (services.msc), in IIS manager you can manage your service.

 
Search
Recent Posts
Create Amazon ElasticCache Using Memcached in CSharp
Nov 21 2017 12:09PM Posted By Amose
Get Google Map Lat Lng (Geo Point) By Pincode in C#
Nov 8 2017 10:26AM Posted By Pranav
Google URL Shortener in C#
Oct 26 2017 10:43AM Posted By Sanjay
Bind Gridview from CSV file in Asp.Net C#
Jun 18 2017 11:38PM Posted By Michael
Call WebService method from jQuery in every 1 minute
Feb 27 2017 11:51AM Posted By John
Gridview custom CSS in ASP.Net
Feb 25 2017 10:59AM Posted By Micheal Ryan
Read excel file and bind to Gridview in C#
Feb 25 2017 10:20AM Posted By Micheal
Tags
Follow us on Facebook
Follow us on Google +
Recent post in your Email inbox.
Enter your email address: