In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the example analysis of the .NET background timing service framework, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let's take a look at it.
Background services as long as experienced developers have come into contact with, which can not be separated from service creation, scheduling logic processing, business logic writing and other links. Often when we create a new background service project, we will copy the previous code, write some threads to complete it, and then deal with the installation of the service. Most of the time is wasted on these repetitive tasks.
What is provided here is a simple background service processing framework, which is supported by a simple background service processing box (executed at a specified interval; once a day at a specified time; and once a day at a specified time Specify the start and end time every day and execute at the specified interval), when developing new scheduled service tasks, you only need to implement the methods of abstract classes, add task configuration and run installation scripts to complete the development of a service.
The framework supports configuring execution types to control the execution logic of tasks
Execute at specified intervals
Execute once a day at a specified time every day
Execute once at a specified time
Specify the start and end time every day and execute at the specified interval
The following is a task that executes stored procedures on a regular basis.
Inherit the base class and write business logic code
Using DataAccessHelper.SQLHelper;using Services.Common;using System Namespace Services.Tasks {public class CallProcTask: ServiceBase {protected override void Exec () {try {if (_ isStart) {if (! string.IsNullOrWhiteSpace (Config.Param)) {LogFactory.GetLogger () .Info (string) .Format ("start executing stored procedure {0}" Config.Param)) SQLHelperFactory.Instance.ExecuteNonQuery (Config.Param, null); LogFactory.GetLogger () .Info (string.Format ("execute stored procedure {0} complete", Config.Param)) } catch (Exception ex) {LogFactory.GetLogger () .Error (string.Format ("execute stored procedure {0} exception: {1}", Config.Param, ex));}
Configure the service name
Configure an interval of 60 seconds for each execution
[{/ / cycle execution task interval 60 seconds "ServiceName": "CallProcTask-proc_test task", / / service name is not empty "Assembly": "Services.exe", / / assembly is not empty "Methods": "Services.Tasks.CallProcTask", / / class name corresponding to the execution class name is non-empty "S_Interval": 60 memory stroke / interval time unit second "ExecType": 0 / / execution type (0: execute at a specified interval 1: execute at a specified time every day 2: execute at a specified time 3. Specify the start and end time every day and execute at the specified interval) the default is 0 "Param": "proc_test" / / the custom parameter is the SQL parameter in this case.]
After writing, compile and run: Install.bat will see the corresponding service in the service manager.
Thank you for reading this article carefully. I hope the article "sample Analysis of .NET background timing Service Framework" shared by the editor will be helpful to you. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.