0

I am trying to call async method from property. my code is

  private Command _forgotCommand;
  public Command ForgotCommand
  {
    get
     {
       return _forgotCommand ?? (_forgotCommand = new Command(ForgotCommandAssetCommand));
     }
  }

  private async void ForgotCommandAssetCommand()
  {
    await ForgotPasswordApiCall();
  }

Now i want to use Task instead of void ( private async void ForgotCommandAssetCommand()) in this line .it gives me error as "Task has wrong return type" Any Suggestions?

dur
  • 15,689
  • 25
  • 79
  • 125
JohnWick
  • 241
  • 2
  • 13
  • 2
    You probably need to make the `ForgotCommandAssetCommand` return a `Task` instead of `void`, but bear in mind that doing the transition between async code and synchronous code is fraught with peril and headache. – Lasse V. Karlsen Aug 24 '18 at 06:34
  • 3
    And your question seems slightly wrong, as you're not really going to call the async method from the getter, instead you're trying to construct a `Command` object around your method, which doesn't work. – Lasse V. Karlsen Aug 24 '18 at 06:39
  • Are you sure you want to do this? See [this](https://stackoverflow.com/questions/12144077/async-await-when-to-return-a-task-vs-void) SO question about async and await. – Jeroen Heier Aug 24 '18 at 14:49

0 Answers0