Public class TimerJob
{
ILog logger.=that the LogManager GetLogger (" errorMsg ");
String timerXmlUrl=AppDomain. CurrentDomain. BaseDirectory + "TimerSpace \ \ TimerConfig XML";
Public TimerJob ()
{}
Public void the Start ()
{
Logger. Error (DateTime. Now. ToString (" yyyyMMdd HH: mm: ss ") + "TimerJob Start ()" + "\ r \ n");
Try
{
The Timer Timer=Timer=new Timer (1000 * 60 * 60 * 4);
The timer. The AutoReset=true;
The timer. Enabled=true;
The timer. Elapsed +=new ElapsedEventHandler (OnElapsedEvent);
The timer. The Start ();
}
The catch (Exception e)
{
Logger. Error (DateTime. Now. ToString (" yyyyMMdd HH: mm: ss ") + "timer Error! ErrorMsg: "+ e.M essage +" \ r \ n ");
}
Logger. Error (DateTime. Now. ToString (" yyyyMMdd HH: mm: ss ") + "end of TimerJob Start ()" + "\ r \ n");
}
///& lt; Summary>
///Timer Elapsed event execution method
///& lt;/summary>
///& lt; Param name="sender" & gt;
///& lt; Param name="e" & gt;
Private void OnElapsedEvent (Object sender, ElapsedEventArgs e)
{
Logger. Error (DateTime. Now. ToString (" yyyyMMdd HH: mm: ss ") + "timer implementation!" );
}
}
CodePudding user response:
Not immediate execution, the time interval is executed, see you after that time interval is 4 hours to perform, can be manually invoked a OnElapsedEvent,As follows:
The Timer Timer=Timer=new Timer (1000 * 60 * 60 * 4);
The timer. The AutoReset=true;
The timer. Enabled=true;
The timer. Elapsed +=new ElapsedEventHandler (OnElapsedEvent);
The timer. The Start ();
//immediately perform a
OnElapsedEvent (null, null);
CodePudding user response:
The Timer Timer=Timer=new Timer (1000 * 60 * 10)