Search code examples
androidmvvmcross

MvvmCross / MvxNotifyTask callback on task finished


Let's assume I have MvxNotifyTask used like here:

MyCommand = new MvxCommand(
   MyTask = MvxNotifyTask.Create(
      asyncAction: () => MyLoooongRunningAsync(),
      onException: ex => OnTaskException(ex)
   );
)

MyCommand is executed after button click.
After MyLoooongRunningAsync I want to call sth like this (in short):

myTextView.Text = "task done";

Where should I put this call?
Does MvxNotifyTask support calling action after task is done?

Thanks!


Solution

  • It does not have that, but you can just wrap your task in another one and make the after action there, e.g.:

    MyCommand = new MvxCommand(
       MyTask = MvxNotifyTask.Create(
          asyncAction: () => MyTask(),
          onException: ex => OnTaskException(ex)
       );
    )
    
    private async Task MyTask()
    {
        await MyLoooongRunningAsync();
        myTextView.Text = "task done";
    }
    

    HIH