Home > Net >  C # System. The Timers. The Timer in the binding event does not perform
C # System. The Timers. The Timer in the binding event does not perform

Time:09-29

Code is as follows, used in the asp.net System. Timers. The Timer set the Timer, when the time interval in under 10 minutes, the Timer event can normal execution, OnElapsedEvent events in the log output to normal, but at the time of interval more than 10 minutes, OnElapsedEvent event log of the output will only perform a, even does not perform, but in both cases the Start method of the log normal output, for a great god,
 
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)
  •  Tags:  
  • C#
  • Related