首页 > 代码库 > c#定时任务
c#定时任务
public class Startup
{
public void Configuration(IAppBuilder app)
{
//指定Hangfire使用内存存储后台任务信息
GlobalConfiguration.Configuration.UseMemoryStorage();
app.UseHangfireServer();
app.UseHangfireDashboard();
SetJobs();
}
private static void SetJobs()
{
string UmengMsgPushList = CommonMethod.GetAppSetting("UmengMsgPush");
String[] elementsUmengMsgPush = UmengMsgPushList.Split(‘|‘);
InitUmengMsgPush initUmengMsgPush = new InitUmengMsgPush();
int sum = 0;
foreach (var item in elementsUmengMsgPush)
{
if (!string.IsNullOrEmpty(item))
{
MsgPushInstance msgPushInstance = initUmengMsgPush.GetmsgPushInstance(item);
List<MsgPushParameter> msgPushParameterList = msgPushInstance.GetMsgPushParameter();
foreach (var msgPushParameter in msgPushParameterList)
{
RecurringJob.AddOrUpdate("job" + item + sum, () => msgPushInstance.PushMsgByUID(msgPushParameter.Medictimeslotid), Cron.Daily(msgPushParameter.Hour, msgPushParameter.Minute), TimeZoneInfo.Local, "default");
sum++;
}
}
}
}
可以利用.../hangfire/recurring查看定时任务
c#定时任务