/* ===================================================== ====================================
Although it is simple, we seldom write such an application. Once in a while, I can easily extract this article.
Writing and publishing simple Windows Services on the. NET platform is very convenient.
Create a (VB. NET/C #) project, select Windows Service application... then you can add code in the OnStart class.
If you want to implement the scheduled operation and live real-time listening function, you can use the TIMER class provided by. NET.
The following is a code snippet.
========================================================== ===================================== */
Private void theTimer_Elapsed (object sender, System. Timers. ElapsedEventArgs e)
{If (! ExCondition ())
{Return;
}
Try
{TheTimer. Enabled = false;
MyTransaction ();
}
Catch (Exception es)
{
WriteLog (es. Message );
}
TheTimer. Enabled = true;
}
// Check execution Conditions
Private bool ExCondition ()
{
DateTime dtNow = DateTime. Now;
If (this. currentmode. Equals ("auto "))
{
String [] frev = this. freqvalue. Split (''-'');
Switch (this. freq)
{
Case "2": // 2-hourly
If (dtNow. Minute = 59) & (dtNow. Second <30 ))
{
Return true;
}
Break;
Case "4": // 4-daily,
If (dtNow. hour = int. parse (frev [1]) & (dtNow. minute = int. parse (frev [2]) & (dtNow. second <30 ))
{
Return true;
}
Break;
Case "8": // 8-weekly,