I wrote an ASP.NET system with the Visual Studio 2022 community. But recently a functional module has a strange problem.
Here I have three timing tasks, one is not controllable, and the other two tasks are running normally.
The last time was unable to run in this situation. For example, this task executed systemic logic but did not send messages to users. I did not find related hints in the log.
The following is my code:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
try
{
LogFile.WriteError(DateTime.Now + "Start");
var checkWorkInterval = double.Parse((CachedConfigContext.Current.CheckWorkConfig.Interval * 1000).ToString());
Timer checkWorTime = new Timer(checkWorkInterval);
checkWorTime.Elapsed += new System.Timers.ElapsedEventHandler(CheckWorkEvent);
checkWorTime.AutoReset = true;
checkWorTime.Enabled = Convert.ToBoolean(CachedConfigContext.Current.CheckWorkConfig.MasterSwitch);
}
catch (Exception ex)
{
LogFile.WriteError(DateTime.Now + "error" + ex.ToString());
}
}
protected void Application_End()
{
LogFile.WriteError("Start 0230");
System.Threading.Thread.Sleep(5000);
string strUrl = "http://" + Application["WebApiUri_Authority"].ToString() + "/api/Msg/Post";
string strRec = HttpClientHelper.PostData("", strUrl, "", "", HttpClientHelper.PostContentType.JSON);
}
private void CheckWorkEvent(object sender, ElapsedEventArgs e)
{
var time = (Timer)sender;
DateTime nowDate = DateTime.Now;
try
{
DateTime startDate =CachedConfigContext.Current.CheckWorkConfig.StartTime;//22:00
DateTime endDate =CachedConfigContext.Current.CheckWorkConfig.EndTime;//23:00
if (startDate <= nowDate && nowDate <= endDate)
{
time.Stop();
LogFile.WriteError(DateTime.Now + "Start");
var count = checkworkBll.CheckWorkCreate();
time.Start();
}
}
catch (Exception ex)
{
LogFile.WriteError(DateTime.Now + "error" + ex.ToString());
time.Start();
}
}
After each task stops, I try to restart the program to return to normal. But after a while, it will stop running. I have re -generated Bin files before, will it be caused by this reason?