Ticket T1182144
Visible to All Users

What is the recommended way to handle async operations in ViewControllers?

created 2 years ago (modified 2 years ago)

In my mind, XAF programming model and the usage of ViewControllers in particular leans heavily toward the synchronous side of the synchronous-asynchronous spectrum.

This manifests in ViewControllers only offering non-Task returning virtual base methods as well as IObjectSpace (Specifically the SecuredEFCoreObjectSpace) not offering a way to CommitChangesAsync (and not invoking DbContext.SaveChangesAsync).

Considering that the rest of the dotnet world is steadily moving toward the async programming model and most libraries only offering async methods (Mediatr comes to mind), I always find myself having to fit a square peg in a round hole, coming that much closer to running into deadlocks or program crashes.

I implemented my own IAsyncObjectSpace, SecuredEfCoreObjectSpaceAsync, BlazorModificationsControllerAsync, etc. that I have been able to get away with with several manageable downsides.

Questions:

  • What is the recommended way to handle async operations in ViewControllers?
  • What is the rationale behind keeping things synchronous?

Thanks!

  • Petre
Comments (1)

    Please answer

    Answers approved by DevExpress Support

    created 2 years ago

    Hello, Petre.

    What is the rationale behind keeping things synchronous?

    I would prefer not to dive much into this general programming topic, because async programming is not a panacea, and it also comes at a cost to its users (greater complexity, learning curve, stricter requirements to keep everything async in the calls tack, etc.). As a PM, I certainly do not want to force our user base to run through all sorts of issues async programming imposes by default - this would ruin UX.

    I will just say that for the majority of XAF users and their use-case scenarios synchronous calls are good enough, easy to learn, use, and maintain (also because our users are not writing the next Facebook). For us, this is also a matter of backward compatibility and breaking changes to ViewControllers and related infrastructure. Still, we are using async programming ourselves in our products where it makes sense or necessary (for instance, in Blazor where it is enforced by the platform itself).

    We do not have special "XAF-related" support or recommendations for handling async operations, because standard .NET recommendations are applied here. While we don't have async support in EFCoreObjectSpace at present, this is a matter of time and user demand - we don't consider this as something critical or a high priority at this stage. I must also say that even for XPO where we have async IObjectSpace support, it is used in just a few usage scenarios.

      Comments (3)

        Thank you, Dennis

        Herman (DevExpress Support) 4 months ago

          Hello,

          I'm writing this follow-up to let you know that in v24.2 you can safely execute code from a background thread. The new BlazorApplication.InvokeAsync method will help you avoid concurrency issues in XAF Blazor apps:

          C#
          Task.Run(async () => { await blazorApplication.InvokeAsync(async () => { await Task.Delay(1000); View.ObjectSpace.Refresh(); Application.ShowViewStrategy.ShowMessage("Data refreshed"); }); });

          Best regards,
          Herman

            Hello Herman,

            Yes, I saw that in What's New in DevExpress v24.2 - xaf async api.

            Thank you for the heads up and have a good day.

            • Petre

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.