About system.timer of use

private System.Timers.Timer _timer = null;

if (_timer == null)
            {
                _timer = new System.Timers.Timer();
                _timer.Interval = 1000;
                _timer.Enabled = true;
                _timer.Elapsed += _timer_Elapsed;
                _timer.Start();
            }

  private void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                _timer.Enabled = to false ; // Save for solving perform rapid changes cause problems of data collection 
                GetSource (); 
                IF (_sendcollection =! null ) 
                { 
                    the OnChange (_sendcollection); 
                } 
            } 
            the catch (Exception EX) 
            { 

                PLog.Log.WriteError (ex.Message); 
            } 
            the finally 
            { 
                IF (_timer =! null ) 
                { 
                    _timer.Enabled = to true ;
            // In order to solve the next execution of rapid change issues lead to data collection
 
 
 
 
} } }

 

Guess you like

Origin www.cnblogs.com/daimaxuejia/p/11356780.html