I am coding an OnAppearing method with a while loop and not sure how to do this with the Cancellation token. I have two example code blocks and I am not sure which would be best to use.
One uses the Token and the other does not. Can anyone tell me if there is any difference between the way the two will work and if I should be using one or the other and why?
private CancellationTokenSource _ctsCards;
public async Task OnAppearingAsync1()
{
_ctsCards = new CancellationTokenSource();
var token = _ctsCards.Token;
while (token.IsCancellationRequested == false)
{
await ShowCardAsync();
}
}
public async Task OnAppearingAsync2()
{
_ctsCards = new CancellationTokenSource();
while (_ctsCards.IsCancellationRequested == false)
{
await ShowCardAsync();
}
}
public Stop()
{
_ctsCards.Cancel()
}