多线程 c# 验证失败

Authentication failing with multiple threads c#

我目前正在编写一个提供一些数据库操作的 Web 应用程序。该系统还需要能够处理不同的 databases.The 问题是数据库中的某些字段必须使用来自 RESTful api 的数据进行更新。为了执行这些更新,我使用了一个 Quartz.NET 计划,该计划为每个需要 updated.This 的 table 作业检查是否需要更新相关数据库。如果是,它会从 REST 服务获取信息。当我不使用多线程时,访问 REST-serivce 没有问题。但是当我使用 Quartz.net 时,服务器 returns 某些请求出现 401 错误。这种行为是不一致的,并不总是发生。我正在使用 RestSharper 通过自定义身份验证器进行这些调用以进行摘要身份验证。我在这里得到了这个解决方案:
http://www.ifjeffcandoit.com/2013/05/16/digest-authentication-with-restsharp/

我也在 post 中使用了 auth fixer。

创造工作:

            foreach (KeyValuePair<string, int> tabel in DataParser.getAllTabellenMetRefresh())
        {
            // define the job and tie it to our class
            IJobDetail job = JobBuilder.Create<LocatieUpdater>()
                .WithIdentity("dbUpdaterJob"+count, "group1")
                .UsingJobData("type", tabel.Key)
                .Build();

            // Trigger the job to run now, and then every x seconds
            ITrigger trigger = TriggerBuilder.Create()
              .WithIdentity("myTrigger"+count, "group1")
              .StartNow()
              .WithSimpleSchedule(x => x
                  .WithIntervalInMinutes(tabel.Value)
                  .RepeatForever())
              .Build();
            sched.ScheduleJob(job, trigger);

这段代码中的响应收到 401。

var client = new RestClient(gegevens["Url"]);

        client.Authenticator = new DigestAuthenticator(ConfigAcces.getCredentials()[0], ConfigAcces.getCredentials()[1]);


        var request = new RestRequest(gegevens["request"], Method.GET);
        request.AddParameter("fields", "all");
        request.AddParameter(velden["TagId"], id);
        IRestResponse response = client.Execute(request);

我用 fiddler 查看了请求,但没有真正看到任何有用的东西。非常欢迎任何帮助或提示。 提前致谢!

不完全确定这是如何修复它的,但所有身份验证似乎都通过禁用 SyncronisationContext 的使用并使方法等待任务来工作。

  var request = new RestRequest(gegevens["request"], Method.GET);
    request.AddParameter("fields", "all");
    request.AddParameter(velden["TagId"], id);
        client.UseSynchronizationContext = false;
        IRestResponse response = await client.ExecuteTaskAsync(request);