Directly attached to the code:
/// <the Summary> /// monthly export /// </ the Summary> Private void ExportMonthExcel () { int T = 0 ; // this variable control is not executed first _monthTimer = new new the System.Threading.Timer (Execute, null , Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan); _monthTimer.Change (TimeSpan.Zero, Timeout.InfiniteTimeSpan) ; void execute(object dateTime) { // next month on the 1st morning 7:30 var executeTime DateTime.Now.AddDays = ( 1 - DateTime.Now.Day) .Date.AddMonths ( 1 ) .AddHours ( 7.5 ); // debug mode, for the first time set next execution time access IF (ConfigHelper.Debug) { if (t == 0) { executeTime = DateTime.Now.AddSeconds(3); } } if (t > 0) { try { var columns = this._anomateexcelService.GetAll(); _monthdYTrackANODetail700013TodayService.ExportMonthToExcel(columns, executeTime); } catch (Exception ex) { _logger.Error ($ " monthly export excel task fails, the Message: ex.Message {}, stackTrace: ex.StackTrace {} " ); } } // executed, reset the timer next execution time. _MonthTimer.Change (executeTime.Subtract (DateTime.Now), Timeout.InfiniteTimeSpan); t ++ ; } }
Change main use of the method of the Timer class