Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Best practices execute method async in ViewModel

$
0
0

Hello,

I need that it execute a method async at the beginning in VM, how do it?

example:

      public Command TextCommand { get; }

      public ViewModel()
      {
            TextCommand = new Command(async () => await FunctionExecuteAsync());
        TextCommand.Execute(null)
      }

     private async Task FunctionExecuteAsync() 
     {
        //do something
     }

Or:

     public ViewModel()
      {
         Task.Run(async () => { await FunctionExecuteAsync(); });
      }

     private async Task FunctionExecuteAsync()
     {
        //do something
     }

Wicht its the correct ?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>