As I know using async/await
is equivalent for Task.Run
with TaskScheduler.FromCurrentSynchronizationContext()
. But I faced with embarrassment when try this (Xamarin.Forms environment):
Action ReFocus = async () =>
{
// not work well as next somehow
adresseeEntry.Unfocus();
await Task.Run(() => {});
adresseeEntry.Focus();
};
ReFocus();
This doesn't work like the following code:
Action ReFocus = () =>
{
adresseeEntry.Unfocus();
Task.Factory.StartNew<bool>(() => true).ContinueWith(r =>
{
adresseeEntry.Focus();
}, TaskScheduler.FromCurrentSynchronizationContext());//*/
};
ReFocus();
Maybe on focusing an element is not a very good example. But this is a real situation that I encountered in practice (in the first case, the focus does not happen for some reason).