Top Banner
Home Categories ASP.Net C#.Net JavaScript ADO.Net Excel AJAX VB.Net SQL Server GridView Issues and Exceptions Silverlight Rich Text Editor JQuery DataList Snippets XML New Features .Net 4.0 TreeView
23

DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

Apr 21, 2023

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 1/23

 

HomeCategories 

ASP.Net

C#.Net

JavaScript

ADO.Net

Excel

AJAX

VB.Net

SQL Server

GridView

Issues andExceptions

Silverlight

Rich Text Editor

JQuery

DataList

Snippets

XML

New Features

.Net 4.0

TreeView

Page 2: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 2/23

AJAX Control Toolkit

jQuery Plugins

Third Party Controls

ASP.Net Validators

WCF

Repeater

Regular Expressions

Yahoo API

iTextSharp

FaceBook

Charts

ListView

Tweeter

Google

CSS

SMS

DotNetZip

Crystal Reports

Entity Framework

HyperLink

RDLC Report

SqlDataSource

Menu

YouTube

Twitter

HTML

Page 3: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 3/23

XmlDataSource

ListBox

Tips

DataGridView

Cryptography

Windows Forms

LinkedIn

WebUserControl

RSS Feeds

HTML5

Sitemap

IIS

LINQ

DataPager

URL Routing

SqlBulkCopy

OCR

ASP.Net 4.5

Master Pages

MySQL

CSV

Stored Procedures

JSON

Web Services

Bootstrap

Windows Service

Page 4: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 4/23

SearchEg. Send Email ASP.Net

Eg. Send Email ASP.NetSearch

DataTable

App.Config

Visual Studio

RadioButton

CheckBox

Generic Handler

DropDownList

FileUpload

RadioButtonList

CheckBoxList

Flash

HtmlEditorExtender

Div

Table

ForumsContactSearch

Eg. Send Email ASP.Net

HomeCategories ForumsContact

Page 5: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 5/23

Tutorial to create a simple Windows Service with sampleexample in C# and VB.Net05 Jan 2015   Mudassar Khan0 Comments    2434 ViewsWindows Service

Here Mudassar Ahmed Khan has explained a tutorial to create a simple Windows Service withsample example in C# and VB.Net.

Download

Like

FollowFollow

Page 6: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 6/23

Follow @ASPSnippets

In this article I will explain a tutorial to create a simple Windows Service with sample examplein C# and VB.Net.

The Windows service will support two modes

1. Interval mode: where Windows Service execute a task at regular intervals after some delay

2. Daily mode: where the Windows Service will execute a task at specific (certain) time of day.

 

Creating a Windows Service Project

The very first step is to add a new project of type Windows Service as shown below.

 

Adding App.Config File

Next you need to add an Application Configuration File (App.Config file). This file will be usedto control the Windows Service and make it work in different modes.

9.5kLike Follow 919

Page 7: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 7/23

 After adding the file, you will need to copy the following AppSettings to the App.Config file.

 Below is the description of each AppSetting.

Mode: It is used to set the Mode. There are two types of modes namely Daily and Interval.

IntervalMinutes: It is used when Mode is set to Interval. It consist of the Interval value inMinutes after which the Windows Service will perform a task. In other words it is the delayvalue.

ScheduledTime: This setting is used when the Mode is set to Daily. It is used to notify theWindows Service the time it should perform a task. The value specified is in 24 hour timeformat.

 

Timer Configuration

The following code has to be placed in the Service.cs Class. I am making use of a Timer classbelonging to the System.Threading namespace in order to execute the Windows Serviceperiodically at regular intervals and as well as once a day at specific (certain) time of day.

The Timer has a Callback method which gets triggered automatically when the due time iselapsed.

We will start with importing the following namespaces.

C#

Page 8: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 8/23

 VB.Net

 Below is the Windows Service class with the OnStart and OnStop event handlers.

When the Windows Service starts it calls the ScheduleService method which first reads theMode AppSetting.. There’s a ScheduledTime variable which is set in both modes.

When the Mode is set to Daily then the ScheduledTime is read from the AppSettings. In thecase when the scheduled time is passed, it is updated to same time on the next day.

When the Mode is set to Interval then the IntervalMinutes is read from the AppSettings andthe schedule time is calculated by adding the IntervalMinutes to the Current Time.

Finally the Timer is set to run the scheduled time. When the scheduled time is elapsed, theTimer’s Callback method is triggered which logs the current date and time to a Text file.

Note: While using the above code, you could encounter the following error: The type ornamespace name 'ConfigurationManager' does not exist in the namespace'System.Configuration' (are you missing an assembly reference?).The solution isprovided in my article The type or namespace name 'ConfigurationManager' does not

exist in the namespace 'System.Configuration’.

C#

Page 9: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 9/23

Page 10: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 10/23

 VB.Net

Page 11: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 11/23

Page 12: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 12/23

 

Adding an Installer to the Windows Service

Once the Windows Service is ready to go we need to add the Installer class to our WindowsService as without it, the Windows Service will not install.

4

Page 13: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 13/23

Following are the steps to add Installer class.

1. Right Click the Service1.cs class and click View Designer in the context menu.

 2. Once the Design View is show, you need to right click and then select Add Installer in thecontext menu.

 

Setting the Windows Service Name and StartType

The above action will add an Installer class named ProjectInstaller. Now you need to open theProjectInstaller.Designer class and look for InitializeComponent Method.

In this method we will modify the ServiceName of the Windows Service and also set itsStartType to Automatic, so that along with the computer the Windows Service will startautomatically.

Note: If you don’t set the StartType to Automatic, the default value is Manual and hencethe Windows Service will not start automatically when the machine is started.

C#

Page 14: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 14/23

 VB.Net

 

Making the Windows Service Automatically start after Installation

After the installation one has to start the Windows Service manually through the Services

Page 15: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 15/23

section of My Computer Management.

We can start the Windows Service automatically after installation by making use of theAfterInstall event handler which triggers immediately after Windows Service is installed.

You will need to open the ProjectInstaller class and override the AfterInstall event handler andadd the code to start the Windows Service.

C#

 VB.Net

Page 16: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 16/23

 

Installing the Windows Service using InstallUtil.exe

Once all the processes are complete, we can now build the Windows Service. Once theWindows Service is build you need to find the EXE file in the Debug folder of the Project.

Note: Once the Windows Service is ready for deployment, it is recommended to make

use of the Release version of the EXE file instead of the Debug version.

To find the EXE, simply right click Project and select Open Folder in Windows Explorer. Nownavigate to Bin => Debug folder and look for the EXE file with name same as that of theproject.

 Now copy and build the path in a Notepad (Text) file.

Note: I would recommend to build the command in a Notepad and save it somewhere sothat you can use it multiple times.

 InstallUtil Syntax

 Example:

Now you need to open Programs => Microsoft Visual Studio 2010 => Visual Studio Tools =>Visual Studio Command Prompt (2010).

Note: I am making use of Visual Studio 2010, and hence you need to use the appropriateversion installed on your computer. And make sure you are logged in as Administrator.

Without Administrator rights it would not allow you to install the Windows Service.

In the command prompt window, copy the InstallUtil command from Notepad and right click inthe Command Prompt and click Paste and then press Enter key.

Page 17: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 17/23

Now the Installer will ask for Logon permissions to run the Windows Service and hence youwill need to add Windows Username and Password of user who has appropriate permission.

 

Note: Username must include Domain Name or the Computer name.

 After successful installation you will see the following message.

Simple Windows Service that runs periodically and once a day at specific time using C#and VB.Net

You can find the Windows Service in the Services window. In order to open Services windowin the Run Command type, services.msc and hit enter.

Page 18: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 18/23

 

Uninstalling the Windows Service using InstallUtil.exe

The syntax for uninstalling a Windows Service is very similar to the installation syntax.

InstallUtil Syntax

Example:

After successful uninstallation you will see the following message.

 

Downloads

Download

Page 19: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 19/23

Page 20: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 20/23

Related Articles

ASP.Net Entity Framework Basic Tutorial to SELECT records and display in GridViewHere Mudassar Ahmed Khan has explained with a basic tutorial with an example of bindingGridView by selecting records from Table and attached sample code, how to configure and useEntity Framework in ASP.Net Websites and Web Applications.Local SSRS Report in ASP.Net Tutorial with exampleHere Mudassar Ahmed Khan has explained step by step tutorial with an example and attachedsample code, how to create Local SSRS Reports or in other words RDLC Reports and thendisplay it using ReportViewer control in ASP.Net Web Application using Visual Studio 2010using C# and VB.NetASP.Net Report Viewer control Tutorial with exampleHere Mudassar Ahmed Khan has explained step by step tutorial with an example and attachedsample code, how to use the ASP.Net ReportViewer control to display RDLC or Local SSRSReports in Visual Studio 2008/2010/2012.ASP.Net Form Validation Tutorial to validate Form using Validation Engine jQueryPlugin Here Mudassar Ahmed Khan has provided a tutorial with example that explains how to validateASP.Net form using jQuery Validation Engine Plugin.ASP.Net AJAX SlideShow Extender control Tutorial with Example

Page 21: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 21/23

Here Mudassar Ahmed Khan has provided a tutorial with example on how to use the ASP.NetAJAX Control Toolkit SlideShow Extender control and display image Slide Show without makinguse of Web Service. This technique describes how to build image Slide Show by fetchingimages from Folder or Directory using the ASP.Net AJAX Control Toolkit SlideShow Extendercontrol.

Comments

No comments have been added to this article.

Page 22: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 22/23

Follow @ASPSnippets

Add Comments

You can add your comment about this article using the form below. Make sure you provide avalid email address else you won't be notified when the author replies to your commentPlease note that all comments are moderated and will be deleted if they are

Not relavant to the articleSpamAdvertising campaigns or links to other sitesAbusive content.

Please do not post code, scripts or snippets.

Like

FollowFollow

NameNameEmailEmailCommentComment

Security code:

Add Comment

9.5kLike Follow 919

Page 23: DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table Forums Contact Search

4/13/2015 Tutorial to create a simple Windows Service with sample example in C# and VB.Net | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridVie…

http://www.aspsnippets.com/Articles/Tutorial­to­create­a­simple­Windows­Service­with­sample­example­in­C­and­VBNet.aspx 23/23

What our readers say

Subscribe

Please enter your email address:

Subscribe

© 2015 www.aspsnippets.com All rights reserved | Privacy Policy | Powered by Excelasoft

Solutions 

 

WaynerVery clear and direct. I needed a model and your crystal clear model provided the framework Ineeded. 

Thank you and nice workSumaI will recommend this site to all my friends and juniors..Best site keep it up...AlexisWow. Thank’s your articles are very GOOD!!!KarthikI have been using many of your posts for reference and it’s very easy... Keep doing thiswonderful work...Asif AzizVery nice explanation of Ajax. This was first time I was learning Ajax. I was explained so nicelythat I understand each step in glance