My code declares a cancellation token here in a view model, creates it in the OnAppearing and Cancels in the OnDisappearing:
public partial class DeckTabViewModel : BaseViewModel
{
public CancellationTokenSource cts;
}
Then in OnAppearing:
public partial class DeckTabViewModel : BaseViewModel
{
public async Task OnAppearingAsync()
{
cts = new CancellationTokenSource();
await GetCards(cts.Token);
}
}
And on Disappearing:
public partial class DeckTabViewModel : BaseViewModel
{
public async Task OnDisappearingAsync()
{
cts.Cancel();
}
}
Could someone tell me if this is the correct way to use the Cancellation token and should I in the OnDisappearing, also set it to null?