No.
OnAppearing happens
"immediately prior to the Page becoming visible."
The purpose of async/await is to allow UI-accessing code to be written in a linear fashion - each line must complete before the next line executes - WITHOUT blocking UI. That is, UI events still occur - between each await.
However, the async method (here, OnAppearing), won't return until all of its lines of code have executed.
That means the page won't display until after all the work is done.
The compiler turns the method into a sequence of tasks with continuations.
IMPORTANT CAVEAT:
It is still necessary for each awaited method ("DoLengthDatabaseTaskAsync") to be well-written with async/await as needed. Each of those methods is executed on the UI thread.
If that method goes a long time without itself having awaits, it will block UI during that time.
async/await does this for you:
- Allows you to write code that is still executing on the UI thread, so you can access UI elements without cross-threading issues.
- Allows UI events to occur BETWEEN each
await line.
- If the
awaited method is also async/await, allows UI events to occur between each of its internal await lines.
That's all async/await does. It doesn't magically eliminate all UI blocking.
And it isn't always a substitute for Task.Run. If you need to do a lengthy operation that doesn't access UI elements, use Task.Run. That runs code on a background thread, so you don't have to be concerned with lengthy operations that lack awaits.
Ivan's answer is one approach. Though the explanation given there is partly wrong.
However there is a simpler answer, given that you have a "fire and forget" situation, where you don't need an answer back:
protected override void OnAppearing()
{
base.OnAppearing();
Task.Run(CallAndForgetAboutOutputTaskAsync);
}
Code inside Task.Run is sent to a background thread. The Run immediately returns to the calling method.
Note that I've removed async from OnAppearing declaration. In this simple case, there is no use of await, and there is very little time spent on the ui thread, so there is no need for async (which generates a bit of extra code/overhead).