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,
Int we = int. parse (frev [0]. substring (1, 1 ));
If (dtnow. dayofweek. tostring (). equals (week [we]) & (dtnow. hour = int. parse (frev [1]) & (dtnow. minute = int. parse (frev [2]) & (dtnow. second <30 ))
{
Return true;
}
Break;
Case "16": // 16-monthly,
Int Mm = int. parse (frev [0]. substring (1, frev [0]. Length-1 ));
If (dtnow. day = mm) & (dtnow. hour = int. parse (frev [1]) & (dtnow. minute = int. parse (frev [2]) & (dtnow. second <30 ))
{
Return true;
}
Break;
Default: // No trigger
Return true;
Break;
}
}
Else
{
Switch (this. startpoint)
{
Case "0 ":
Return true;
Break;
Default:
String [] ST = startpoint. Split ('-');
If (dtnow. hour = int. parse (ST [0]) & (dtnow. minute = int. parse (ST [1]) & (dtnow. second <30 ))
{
Return true;
}
Break;
}
}
Return false;
}
Register your Windows service program.
Use installutil iasserver.exe (this file is under C:/winnt/Microsoft. NET/framework/v1.1.4322 by default)
Installutil iasserver.exe
Installutil iasserver.exe/U (unmount)