Skip to content

Question: Cancellation #59

Answered by johnthiriet
ModernRonin asked this question in Q&A
Discussion options

You must be logged in to vote

Hello,

This might not be the best place to ask a question as it is not an issue per say but here is what you can do in pseudo code.

class ViewModel 
{
  CancellationTokenSource _cts;
  AsyncCommand StartCommand(async () => {
   try  {
     _cts?.Cancel();
    _cts?.Dispose();
    _cts = new CancellationTokenSource();
    StartYourProcessThatHasCancellationAsync(_cts.Token);
   }
   finally {
     _cts?.Dispose();
    _cts = null;
   }
  }
  
  AsyncCommand StopCommand(() => {
     _cts?.Cancel();
  });
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by brminnick
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #58 on March 03, 2021 17:11.