cslaforum
cslaforum copied to clipboard
Marking [Fetch] Method Async
Question Hi. I wanted to check with you, if you see any possible issues in marking the [Fetch] method Async similar to the below line?
[Fetch] private async void Fetch(int id)
Version and Platform CSLA version: 5.1.0 OS: Windows Platform: WinForms, WPF, ASP.NET Core
As I understand it, no reason to make the Fetch method async. The DataPortal.FetchAsync will handle this correctly.
It needs to be
[Fetch]
private async Task Fetch()
Never have async methods return void unless it's an event handler.
True - and in this particular case, the data portal specifically looks for async Task and won't invoke the method if it is async void.
Also, fwiw @JacoJordaan, you are right - the client-side data portal should be used async (FetchAsync, etc.) as a general rule.
And on the server-side you can also have async methods, which is often necessary because you'll be using Dapper, EF, or other APIs that require the use of the await keyword - so you need the server-side method to be async Task.