Ticket T1251767
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

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

SimpleAction does not open view if execute method contains await

created 7 months ago

Hello,
I have an asynchronous action in my application so i can use other asynchronous methods inside it and await them. This works generally fine, but if I want to use e.ShowViewParameters.CreatedView to show a view after the action is completed, if the execute method contains any awaits, it will not open the view.

I have attached a test project that showcases this behavior in both Blazor and WinForms. If you click on the Test Action it does not open a view. However, if you remove the await from the execute function, it works just fine.

Answers approved by DevExpress Support

created 4 months ago (modified 3 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"); }); });

For more information, review the docs with code examples at InvokeAsync | Refresh Data in a View After a Period of Time (ASP.NET Core Blazor).

Best regards,
Herman

P.S. e.ShowViewParameters.CreatedView will still not work with this approach, but you show a view in other ways: https://docs.devexpress.com/eXpressAppFramework/112803/ui-construction/views/ways-to-show-a-view/ways-to-show-a-view.

    created 7 months ago (modified 7 months ago)

    Hello, Bernd.

    Thanks for your feedback.
    We have no special support for this type of scenario in the current XAF version and cannot offer good solutions, sorry. I elaborated more on this in What is the recommended way to handle async operations in ViewControllers? and Re: What is the recommended way to handle async operations in ViewControllers?, and we also keep tracking similar user requests (not many at this stage, so thank you for the sample). In certain cases, synchronous calls may help (Task.Run, TaskFactory, .Result, .GetAwaiter), but not in all the scenarios, like this one.

    Should market demand for this feature/capability change, we will definitely consider it. In the meantime, we remain focused on the features/capabilities outlined in our product development roadmap.

    C#
    private async void Action_Execute(object sender, SimpleActionExecuteEventArgs e) { Task t = new Task(() => System.Threading.Thread.Sleep(100)); t.Start(); await t; var os = Application.CreateObjectSpace<TestObject>(); var ob = os.CreateObject<TestObject>(); e.ShowViewParameters.CreatedView = Application.CreateDetailView(os,ob); Console.WriteLine("Action Finished"); }

    You can find additional information on handling other asynchronous operations in XAF Blazor in the following tickets:

      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.