我需要在Run()
方法内调用Main()
吗?因此它将在代码中提到的时间每天调用。
public class Program
{
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
static void Main()
{
var host = new JobHost();
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
// This method will be called on weekly basis
public static void Run([TimerTrigger(typeof(MyDailySchedule))] TimerInfo timerInfo, TextWriter log)
{
log4net.Config.XmlConfigurator.Configure();
try
{
MainA.Wait();
}
catch (Exception ex)
{
}
}
static async Task MainA()
{
WebJob1 Service = new WebJob1();
await Service.DeletData();
}
}
public class MyDailySchedule : DailySchedule
{
public MyDailySchedule() :
//Schedule
base("2:00:00", "14:00:00", "15:00:00")
{ }
}
您无需使用WebJobs SDK即可实现。相反: