0

We are have a Kentico CMSAbstractWebPart that interacts with a 3rd party service. The service historically used SOAP but has moved to JSON (an thus is async now).

All of our low-level commands are of type Task. To execute them outside of Kentico we invoke the calls with:

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

However, when inside of Kentico, this will cause deadlocks with the UI. We are trying to use Kentico's AsyncWorker, but can't find the correct methods / parameters.

Here is an example of what we are trying:

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

Any guidance you could give would be GREATLY appreciated!

Thank you!

Doldrums
  • 11
  • 1
  • What type of application is yours? ASP.NET MVC? ASP.NET Web Forms? How is `Task.Run` deadlocking? How are you invoking it? – Paulo Morgado Jan 27 '20 at 08:25
  • I see abstract web part so I assume web forms. Async worker is Kentico wrapper on creating and running delegate in a separate thread. WebForms lifecycle and async actions alone can be very tricky on their own. What type of deadlocks are we talking about? Worker threads deadlocks on resource access? How many requests can service respond to at the same time? It could be that it is queried too much and simply can not reply to all tasks fired at once, but that is just an assumption. What parameters are you trying to pass to worker? – Michal Samuhel Jan 27 '20 at 15:35
  • Paulo - thanks for the response. This is in a special CMS called Kentico, which has to use WebForms and your webpart has to descend from CMSAbstractWebPart. It is a special beast of its own. – Doldrums Jan 27 '20 at 16:56

1 Answers1

1

There are two things might be worth checking:

1) Check \Web\CMS\CMSPages\PortalTemplate.aspx file so that it should contain Async="true" attribute on Page:

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

2) In any case, your web part code will be called synchronously anyway, have you tried explicitly call it synchronously as described in this article?

Dmitry Bastron
  • 694
  • 3
  • 11
  • Thanks for the ideas. `Async="true"` did not seem to help. Our code has used both `Task.Run(async () => { await task; });` as well as `task.GetAwaiter().GetResult()` It completely crashes the Kentico IIS session. – Doldrums Jan 27 '20 at 18:58
  • You need get the exception. It looks like it is crushing silently and you dont have the exception. Take a look at https://stackoverflow.com/questions/9343594/how-to-call-asynchronous-method-from-synchronous-method-in-c – Peter Mogilnitski Jan 27 '20 at 20:41
  • Im working on a WebPart and had no idea how to set Async="true". Did a lot of searching, this is the first answer to point me at "\Web\CMS\CMSPages\PortalTemplate.aspx", which worked for me – Design.Garden May 01 '21 at 02:37