Replies: 4 comments
-
I agree with this point, but when you look at the API's which you have mentioned most of them are top event handlers and it's a good practice to use |
Beta Was this translation helpful? Give feedback.
-
@dishantmshah, the handler of those events can be |
Beta Was this translation helpful? Give feedback.
-
It can properly affect performance in a bad way and it is pretty easy to make it async on your own. |
Beta Was this translation helpful? Give feedback.
-
I agree with you on this point, but I think it's for a good reason, as I said actual apps always will need to do async operations. As you can see here Tasks can be 15% slower than sync methods. But, maybe, we can use the
I disagree with you here, to me, pretty easy means add the async/await keyword and everything works like a charm, sadly this isn't always true, for some scenarios I'll use those ones that I used on my spec. The first one is The second one is Shell.Navigating event, here it's simple (at first glance) I just need to add the async and done, right? No. Let's take a look at this. async void OnShellNavigating(object sender, ShellNavigatingEventArgs e)
{
var result = await DisplayAlert("Alert", "Are you sure?", "Yes", "No");
if (!result)
e.Cancel();
} Reading this code, you can assume that if the user taps on the "No" button option, the navigation doesn't occur. But the practical behavior is different when the DisplayAlert appears, the rest of the code runs, the navigation occurs and the user response doesn't have any effect. As you can see some scenarios aren't pretty easy to make it async. Maybe I don't see an easy way here, because I'm missing something, if so please let me know. |
Beta Was this translation helpful? Give feedback.
-
I don't know if this name represents my proposal, feel free to change it. (I'm terrible naming things)
Change some events and methods to
Task/Task<T>
Today is practically impossible to have a real app without async code (aka.
Task
andTask<T>
) and the XF has a lot of APIs that weren't built in this way and, sometimes, we have a hard time to use them with async code.My proposal is to change the return of those APIs to
Task
orTask<T>
(when it's possible). To illustrate better this scenario I can use theOnBackButtonPressed
, it's a virtual method inside thePage
class.Since this method returns a
bool
it's very hard to do some async operation inside it. Also withvoid
methods, this can be tricky, for example in Shell theOnNavigating
event, if you want to show a pop-up to ask the user if he wants to leave the page.In this example, when the DisplayAlert appears, the navigation occurs, so we don't have the user's input.
API
Here I'll list some methods/events that would be good to have async support. For events, maybe we can use
Func<Task>
.Scenarios
C# Example
Difficulty : [low/medium/high]
Medium
Beta Was this translation helpful? Give feedback.
All reactions