Kentico-AsyncWorker(运行任务)

问题描述 投票:0回答:1

我们有一个与第三方服务交互的Kentico CMSAbstractWebPart。该服务过去使用SOAP,但已迁移到JSON(因此现在是异步的)。

我们所有的低级命令都是Task类型的。要在Kentico之外执行它们,我们使用以下方法调用这些调用:

Task.Run(async () => { await task; });

但是,在Kentico内部,这将导致UI死锁。我们正在尝试使用Kentico的AsyncWorker,但找不到正确的方法/参数。

这里是我们正在尝试的示例:

AsyncWorker worker = new AsyncWorker();
worker.RunAsync(task, System.Security.Principal.WindowsIdentity.GetCurrent());
worker.WaitForFinish();

您可以提供的任何指导将不胜感激!

谢谢!

c# async-await kentico
1个回答
0
投票

可能有两件事值得检查:

1)检查\ Web \ CMS \ CMSPages \ PortalTemplate.aspx文件,使其在页面上应包含Async =“ true”属性:

<%@ Page Language="C#" AutoEventWireup="true" Inherits="CMSPages_PortalTemplate" Async="true"
ValidateRequest="false" MaintainScrollPositionOnPostback="true" EnableEventValidation="false"
Codebehind="PortalTemplate.aspx.cs" %>

2)无论如何,您的Web部件代码无论如何都将被同步调用,您是否尝试像this article中所述显式地同步调用它?

© www.soinside.com 2019 - 2024. All rights reserved.