Hi,
This is a response to https://supportcenter.devexpress.com/ticket/details/t1182144
which is marked as duplicate of https://supportcenter.devexpress.com/ticket/details/t1178668
However, that ticket is marked private and can not be opened.
Anyway, it is sync / async discussion with Dennis finishing with:
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).
And this is exactly the culprit - Blazor.
Platform forces async, but XAF does not support it in view controllers with async methoed overrides which can lead to severe issues.
For instance, I have custom property editor which uses JavaScript (which uses async based pdf.js) control and is communicating with Blazor using JSInterop to get back the data - and JSInterop is async only, there is not even an option to run JSInterop in sync mode.
Control is designed to load PDF file and to receive a bitmap stamp and then allow user to resize and reposition the stamp - each move and resize is a singular property changed event which would cause a demanding process in the background (merge PDF with bitmap, seralize and return it as base64 string) - so I thought I would only mark objecspace as modified in those events and perform actual data retrieval in ObjectSpace_Committing event (basically, when user clicked Save button).
And this is where I am stuck now because I need to call async method in Objectspace_Committing which retrieves data from JavaScript component using JSInterop.
If I mark ObjectSpace_Committing as async - it does not work because ObjectSpace is disposed when method gets executed.
Any other method (Task.Run, TaskFactory, .Result, .GetAwaiter) causes deadlock.
XAF Blazor really needs full async support since platform enforces it.
Regards,
Mario
Hi, Mario.
Looking at my own words that you cited, today I think that they can be interpreted incorrectly or lead to tickets such as this - I do apologize for the confusion.
While I would still love to have full async support in XAF Controllers and core entities from the first release of XAF Blazor UI (it never hurts to have an extra feature), I would avoid generalizations such as "severe issues" and "needs full async support". I am estimating this as a product manager involved in architecture and development for this framework, and also because:
To make a long story short, my team and I will be happy to make a cursory review of a small modified MainDemo.EFCore app (easily debuggable and runnable) where you tried to integrate pdf.js with a custom property editor, but failed. Please also use English names for all methods and variables, and include screenshots, user steps, text descriptions to clarify your ultimate goal from an end-user perspective (omit
ObjectSpace_Committing
,mark objecspace as modified
and other non-working things you tried). If you have a non-XAF app that does what you need, attach it as well for reference. With that, we will be able to give the best recommendations for the current XAF version or consider specific framework enhancements for the future. Thanks.Just my 2c on this:
I wouldn't say (can't believe) that the cases where async is needed is less than the number of fingers on a hand. Almost everything is async nowadays. Just try to use an external library that relies on async or reuse your own services that rely on async (which can clearly happen nowadays) and you are out of luck. At least we are searching for solutions every now and then.
Currently, we have a SimpleAction where we want to call an async service inside the Execute handler. We have the same problem of deadlocks while trying to work around this limitation (Task.Run, TaskFactory, .Result, .GetAwaiter).
simply making the Execute handler async and awaiting the service seems to do something but never returns nor does a catch block work. You are mentioning that this is not a problem at all and we should simply work around this. Perhaps it's a lack of knowledge on our side but we are having a problem here.
Can you please share your knowledge about this workarounds you mentioned with us or how to correctly tackle this situation?
Thanks!
Thanks for jumping in, Andreas. Sure, we will be happy to. For this, please create a separate SC ticket (https://devexpress.com/ask) and describe your specific use-case scenario with a specific external library or service, provide required user steps and expected results for each step for you as a developer and end-users (their ultimate goal). If possible, please attach a modified MainDemo.Blazor or another simple test app where you added required service dependencies and tried to call it from XAF Controllers. With that, we will be able to give you specific recommendations or the best practices for your particular case. I am afraid we cannot assist you much based on a general info:
Regards,
Dennis
I'll join the conversation, if I may.
I can't speak for others, obviously, but I have had many cases of requiring async support in my XAF Blazor apps for which I have always found a sub-optimal, ugly solution which produces undesired side effects.
Can it be that people are not reporting what they're struggling with… Or that they're not struggling and we are the only people who do.
Hi Petre,
considering how many issues I do not report (and I still report a lot), I would guess many people do the same - it is just the matter of how annoyed their customers are and whether those issues translate into support phone calls which also depends on type of application - whether it is some not business critical helper app or is it financial app, much more business critical.
I guess you need to find yourself in a position where you have fairly business critical app, issues that results in a lot of support phone calls, but not enough resources to tackle all issues by yourself.
Regards,
Mario
Hi Dennis,
Just to give you one more data point: Our apps also frequently interact with external services, all async (e.g. load/send some data via REST or a just a long running SQL query). Took me a while to figure out how to do that the best way in XAF Blazor with the given architecture. I would also be happy to have better built-in support for this.
Regards,
Piero
Thank you for your feedback, Piero. Please share your current solution with other XAFers here, if possible (just a code snipped or attach your full Controller code).
Viewcontrollers should have async support.
For example: