Rule of thumb says: if it's not a UI related method, use Task.ConfigureAwait(false)
.
What if I have a PCL core library which accepts an interface IUIAccess
.
The view model in the core library then has a method:
public Task ViewModelLoginAsync()
{
bool success = await loginService.ServiceLoginAsync();
if(!success)
{
uiAccess.ShowInfoDialog("Login failed.");
}
}
IUIAccess
would show a UIAlertView
on iOS.
My assumption would now be: if I call ViewModelLoginAsync
from my UIViewController
I should not configure await to FALSE. It clearly is UI code.
However the call to ServiceLoginAsync
could use configure await false. Is this correct?
Is it just good practice or really recommended because of performance, memory usage, ...?
First, I recommend (as much as possible) not to call from the VM into the view. I would prefer to use data binding or a message bus of some kind.
That said, you would not use ConfigureAwait(false)
in ViewModelLoginAsync
, since it needs to resume on the UI context (this is also true if you update via data binding instead of an explicit call). However ServiceLoginAsync
should use ConfigureAwait(false)
for the reasons I describe in my MSDN article (primarily performance).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With