I remember a long time ago, a colleague had to write a scheduled task. First, when a piece of news arrives at a set timeProgramAutomatic deletion
I have no idea whether I can solve this problem.
Later, I found a method some time ago: http://www.cnblogs.com/ucetgg/archive/2009/02/11/1388481.html
This is not very good. Some senior people also replied to me and pointed out their ideas. Using Windows service, I have never written
Later I saw an articleArticle: Http://www.cnblogs.com/lovecherry/archive/2005/03/25/125527.html
I used Windows Service as a keyword to search for blogs. Many people have already done this.
I will not elaborate on the steps. Post myCodeCome out:
Code
Namespace Windows Service
{
Public Partial Class Service1: servicebase
{
Public Service1 ()
{
Initializecomponent ();
}
/// <Summary>
/// Start
/// </Summary>
/// <Param name = "ARGs"> </param>
Protected Override Void Onstart ( String [] ARGs)
{
// Thread t = new thread (New threadstart (run ));
// T. Start ();
Timer1.enabled = True ;
Exectask ();
}
/// <Summary>
/// End
/// </Summary>
Protected Override Void Onstop ()
{
Timer1.enabled = False ;
}
Private Void Timersponelapsed ( Object Sender, system. Timers. elapsedeventargs E)
{
Thread t = New Thread ( New Threadstart (exectask ));
T. Start ();
}
/// <Summary>
/// Execute task
/// </Summary>
Private Void Exectask ()
{
String Strsql = " Insert into website_cmscontent (title, body) values ('TT', 'xx ') " ;
Dbhelpersql. executesql (strsql );
}
}
}
Note:
1.Timer controls must beSystem. Timers. Timer type
2.Installutil.exe must correspond to the Framework version. For example, the installutil tool in the f ramework 2.0 program version 1.1 won't work.
3.By default, the service is not automatically started and needs to be manually started after the installation is successful.