I have the following simple class:
public sealed class TimeStampTestViewModel : ObservableObject
{
private CancellationTokenSource cancellationSource;
public TimeStampTestViewModel()
{
this.cancellationSource = new CancellationTokenSource();
PeriodicTimeStampChanged(cancellationSource.Token);
}
public string TimeStamp
{
get
{
return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
}
private async void PeriodicTimeStampChanged(CancellationToken token)
{
while (!token.IsCancellationRequested)
{
RaisePropertyChanged("TimeStamp");
await Task.Delay(500, token);
}
}
}
Will an instance of this class ever be garbage collected? Or will the presence of the infinite running task block garbage collection?