Go to File -- > New -- > Project -- >Visual C# -- > Windows -- > Windows Service .
Then Create a New Project. It shows(Service1.cs),
Then Right Click and Click the Add Installer bar, ProjectInstaller.cs File will be created
Its having two controls, ServiceProcessInstaller1, and ServiceInstaller1
In ServiceProcessInstaller1 == > Go to Properties and Modify Account as Local Service . It is aoid the Set Service Login prompt being asked about the system username and password
In ServiceInstaller1 ==> Go to Properties and Modify StartType as Automatic , Servicename à Your Service Name , Display Name ( This name is shown in the Services), Description (This Name is shown in the Services)
Right Click Windows Service Project and Add Folder and file called CommonBehaviours.cs
CommonBehaviours.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace WindowsService.Function { public class WriteToFile { public void WriteToFile1() { string strDateTime = DateTime.Now.ToString(); StreamWriter sw = new StreamWriter(Path.Combine("D:\\temp\\", "Suresh.txt"), true); sw.WriteLine(strDateTime); sw.Close(); } } }
Service1.cs
using System; using System.ServiceProcess; using System.Timers; namespace TestWindowsService { partial class Service1 : ServiceBase { //Make the service at particular time period Timer TimerObj = new Timer(ConvertMinutesToMilliseconds(30)); public Service1() { InitializeComponent(); } protected override void OnStart(string[] args) { // TODO: Add code here to start your service. TimerObj.Elapsed += new ElapsedEventHandler(OnElapsedTime); TimerObj.Enabled = true; } protected override void OnStop() { // TODO: Add code here to perform any tear-down necessary to stop your service. TimerObj.Enabled = false; } protected void OnElapsedTime(object source, ElapsedEventArgs e) { //Write the current datetime to the file WindowsService.Function.WriteToFile objWriteToFile = new WindowsService.Function.WriteToFile(); } public static double ConvertMinutesToMilliseconds(double minutes) { return TimeSpan.FromMinutes(minutes).TotalMilliseconds; } } }
How to start service in Code
Go to ServiceInstaller1 -- > Create an event , Write a code to start the service like shown below.
create Service Installer
Ritht Click the Projects Solution -- > Add New Project -- > Go to Other Project Types -- > Setup and Deployment -- > Choose the Setup
Then follow the below steps
Then Double Click the Application Folder
Then Double Click the Primary output (from your service name)
Press ok . Then see the Setup Properties F4 (need to setup like below).It shown like below
Manufacturer will come in path as "C:\Program Files\ManufacturerValue"
Title will come in Setup Wizard
The Right Click and go to the Properties Set the Configurateion dropdown and Configuration Manager to Release Mode
Then our Installation steps :
Then Click Next and Finally Complete the Installation (click Close)
Finally the services is shown below
Now the Service is created and run successfully right.
05:27 |
Category:
Concepts
|
16
comments
Comments (16)
Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
rpa training in chennai | best rpa training in chennai | rpa training in chennai | rpa training in bangalore
rpa training in pune | rpa online training
Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article. thank you for sharing such a great blog with us.
Data Science training in Chennai | Data science training in bangalore
Data science training in pune| Data science online training
Python training in Kalyan nagar
Impressive. Your story always bring hope and new energy. Keep up the good work.
java training in chennai | java training in bangalore
java online training | java training in pune
Nice tips. Very innovative... Your post shows all your effort and great experience towards your work Your Information is Great if mastered very well.
python training in rajajinagar
Python training in btm
Python training in usa
Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.Best Devops Training in pune
Devops interview questions and answers
Mind blowing content!! Thanks for uploading
Selenium Training in Chennai
selenium Classes in chennai
iOS Training in Chennai
Digital Marketing Training in Chennai
Android Training
Android Training in Chennai
Big Data Training in Chennai
Great Blog. Each and every steps are Uniquely Created. and the Concept was easily able to understand.
Data Science Training Course In Chennai | Data Science Training Course In Anna Nagar | Data Science Training Course In OMR | Data Science Training Course In Porur | Data Science Training Course In Tambaram | Data Science Training Course In Velachery
"Thanks for sharing this article. Really helpful for me..
Digital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery
"
Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
Java training in Chennai
Java training in Bangalore
Java training in Hyderabad
Java Training in Coimbatore
Java Online Training
Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites!
hardware and networking training in chennai
hardware and networking training in velachery
xamarin training in chennai
xamarin training in velachery
ios training in chennai
ios training in velachery
iot training in chennai
iot training in velachery
It¦s truly a nice and helpful piece of info. I am satisfied that you simply shared this helpful information with us. Please keep us informed like this. Thanks for sharing.
sap training in chennai
sap training in tambaram
azure training in chennai
azure training in tambaram
cyber security course in chennai
cyber security course in tambaram
ethical hacking course in chennai
ethical hacking course in tambaram
I like the blog format as you create user engagement in the complete article. Thanks for the informative posts.
oracle training in chennai
oracle training in annanagar
oracle dba training in chennai
oracle dba training in annanagar
ccna training in chennai
ccna training in annanagar
seo training in chennai
seo training in annanagar
First i got a great blog .I will be interested in more similar topics. i see you got really very useful topics, i will be always checking your blog thanks.
hardware and networking training in chennai
hardware and networking training in porur
xamarin training in chennai
xamarin training in porur
ios training in chennai
ios training in porur
iot training in chennai
iot training in porur
A very useful content indeed ! thanks for sharing with us!
data science training in chennai
ccna training in chennai
iot training in chennai
cyber security training in chennai
ethical hacking training in chennai