Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#Quartz调度方法异步_C#_Asp.net Mvc_Quartz Scheduler - Fatal编程技术网

C#Quartz调度方法异步

C#Quartz调度方法异步,c#,asp.net-mvc,quartz-scheduler,C#,Asp.net Mvc,Quartz Scheduler,我有一个async方法,计划每10分钟运行一次。然而,它只是第一次运行 应用程序启动 protected void Application_Start() { ... JobScheduler.Start().GetAwaiter().GetResult(); } 作业调度程序 public static class JobScheduler { public static async Task Start() { try {

我有一个
async
方法,计划每10分钟运行一次。然而,它只是第一次运行

应用程序启动

protected void Application_Start()
{
    ...
    JobScheduler.Start().GetAwaiter().GetResult();
}
作业调度程序

public static class JobScheduler
{
    public static async Task Start()
    {
        try
        {
            NameValueCollection props = new NameValueCollection
            {
                { "quartz.serializer.type", "binary" }
            };
            StdSchedulerFactory factory = new StdSchedulerFactory(props);
            IScheduler scheduler = await factory.GetScheduler();

            await scheduler.Start();

            IJobDetail job = JobBuilder.Create<Service>()
                .WithIdentity("job1", "group1")
                .Build();

            ITrigger trigger = TriggerBuilder.Create()
                .WithIdentity("trigger1", "group1")
                .StartNow()
                .WithSimpleSchedule(x => x
                    .WithIntervalInMinutes(10)
                    .RepeatForever())
                .Build();

            await scheduler.ScheduleJob(job, trigger);
        }
        catch (SchedulerException se)
        {
            Console.WriteLine(se);
        }
    }
}

我不知道我需要做什么才能连续运行

我的蜘蛛感觉告诉我
调度程序
不在范围内,你的
作业
只运行一次,因为它的
现在开始
然后一切都会被清理干净

尝试调用方法
等待调度程序.Start()在末尾。它应该可以工作。

您是否通过放置断点来调试Execute方法?并确保您已经拥有该目录,如果该目录不存在,则会引发异常
public class Service : IJob
{
    public async Task Execute(IJobExecutionContext context)
    {
        using (StreamWriter streamWriter = new StreamWriter(@"C:\pacote\IDGLog.txt", true))
        {
            await streamWriter.WriteLineAsync(DateTime.Now.ToString());
        }
    }
}