Click here to Skip to main content
15,913,467 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to create a windows service that perform some codes every 30 minutes.so i have added a windows service to my project. then drag a Timer component to it and set its interval property.then i have written my code in Tick event of Timer.finally set Enabled property of Timer to true in onStart event of windows service.
also i have added a setup project to my solution and install it in my system.but the windows service does not work.
please tell me where is my mistake?
Posted
Comments
RaisKazi 3-Sep-11 4:48am    
After installation, Have you started your windows service?
M_Mogharrabi 3-Sep-11 4:51am    
should i start it myself?i thought it starts automatically when windows boots!
How should i start it?
RaisKazi 3-Sep-11 4:57am    
http://msdn.microsoft.com/en-us/library/aa984431(v=vs.71).aspx
M_Mogharrabi 4-Sep-11 0:35am    
thanks RaisKazi,the link was too useful.

Hello Friend...

After installing your service you need to start it....

1) Goto Control Panel..
2) Administrative tools
3) Services
4) Find your service
5) Right Click and start it

6) Now your service will start and working....

other wise
1) Press WindowsKeY + R
2) In Run type it services.msc
3) Then Hit Enter it will open a service manager
4) follow 4 and 5 step to start your service....


or you can also start your service with the finish code of your setup project..

but before that code your service must be installed on your computer..
also you can make your service as start automatically when windows start so it will start after you restart your computer.


I hope this will help you..

For Basic information on services please see this article

Simple Windows Service Sample[^]
 
Share this answer
 
Comments
M_Mogharrabi 4-Sep-11 0:44am    
thanks Tejas_Vaishnav for your reply,but i have another question. should i define my windows service in an independent project or it can be in my main project with other forms?
Tejas Vaishnav 5-Sep-11 1:38am    
phoenix1167...
For that answer i want to know one thing is that for what purpose you want your windows service is used..?? and which type of work your service is provide in timer event..??

but if you create a new service project then its also run that service and also it is possible to create second solutions in your main project as service project like websites of asp.net have this type of architecture....
M_Mogharrabi 5-Sep-11 3:16am    
i want to get backup automatically with my windows service and i used timer to check my backup schedule table every N minutes.
Tejas Vaishnav 5-Sep-11 4:43am    
Hello friend if you want to back up your database then see this link
this is the sql server functionality to backup your database automatically with job scheduler.
http://msdn.microsoft.com/en-us/library/ms191439.aspx

or you can also create a sap rate windows service to back up your db but i will prefer to use sql server functionality...
Instead of timer do the following:
bool running = true;
int time =0;
while(running)
{
    Thread.Sleep(1000);
    time++;
    if(time>30*60*60)
    {
       time=0;
       // do work here
    }
}
 
Share this answer
 
Try not to use a Timer - instead use Sleep to put your service to bed for a while.
C#
DateTime nextDue = DateTime.Now.AddMinutes(30);
While (stillRunning)
   {
   Thread.Sleep(10000);
   if (DateTime.Now > nextDue)
      {
      ...
      nextDue = DateTime.Now.AddMinutes(30);
      }
   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900