函数内部任务。lundo d de dececon

发布于 2025-02-13 08:24:37 字数 1072 浏览 1 评论 0原文

我的代码中有一些缓慢的部分,可以执行HTTP请求,然后等待答案并致电ADF管道,以便在末尾更新数据库参数。由于这花费了2分钟,我的客户端应用程序对于我的客户端似乎是如此慢,所以我在task.run()内包装了此调用,然后将我的逻辑设置在内部。这效果很好,但最后一部分是更新数据库参数,根本无法执行。

Task.Run(async () =>
{
    await client.ExecuteAsync(request, CancellationToken.None);
    await RunADFPipeline(pipeline, _config);
    await _projectRepository.UpdateValue(id, "status", "unlock");
});

我在网上找到了这个示例,并在代码中应用了它。前两个等待似乎正确执行,但第三个根本没有执行。如果我将其设置在task.run()之外,则执行。第三部分实际上只是调用了一个存储过程,

return await _context.Database.ExecuteSqlRawAsync("EXEC core.UpdateValue @ProjectId, @Name, @Value", parameters);

我还尝试了在task.run()末尾添加contine whitwith(),但仍然没有运气。

Task.Run(async () =>
{
    await client.ExecuteAsync(request, CancellationToken.None);
    await _adfHelper.RunADFPipeline(pipeline, _config);
}).ContinueWith((result) => _projectRepository.UpdateValue(id, "status", "unlock"));

所有这些代码都在控制器内。 task.run()完成或完成内部功能后,关于如何实现目标并更新此参数的任何想法和想法?

I have some slow part of my code that does a http request then waits for the answer and calls an adf pipeline so it can update a database parameter at the end. Since this took 2 minutes and my client app seemed so slow for my clients, I wrapped this call inside Task.Run() and set my logic inside. This works good but the last part, update a database parameter, doesn't get executed at all.

Task.Run(async () =>
{
    await client.ExecuteAsync(request, CancellationToken.None);
    await RunADFPipeline(pipeline, _config);
    await _projectRepository.UpdateValue(id, "status", "unlock");
});

I found this example online and I applied it in my code. The first two awaits seem to execute correctly but the third one doesn't execute at all. If I set it outside of Task.Run(), it executes. The third part literally just calls a stored procedure

return await _context.Database.ExecuteSqlRawAsync("EXEC core.UpdateValue @ProjectId, @Name, @Value", parameters);

I also tried by adding ContinueWith() at the end of the Task.Run() but still no luck.

Task.Run(async () =>
{
    await client.ExecuteAsync(request, CancellationToken.None);
    await _adfHelper.RunADFPipeline(pipeline, _config);
}).ContinueWith((result) => _projectRepository.UpdateValue(id, "status", "unlock"));

All this code is inside a controller. Any thoughts and ideas on how can I achieve my goal and update this parameter after Task.Run() finishes or the functions inside finish?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文