public TweetThumbnail()
{
InitializeComponent();
+
+ this.cancelTokenSource = new CancellationTokenSource();
}
public Task ShowThumbnailAsync(PostClass post)
this.scrollBar.Enabled = false;
- this.cancelTokenSource = new CancellationTokenSource();
var cancelToken = this.cancelTokenSource.Token;
-
var uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
this.task = Task.Factory.StartNew(() => this.GetThumbailInfo(post), cancelToken, TaskCreationOptions.None, TaskScheduler.Default)
{
if (this.task == null || this.task.IsCompleted) return;
- this.cancelTokenSource.Cancel();
+ var oldTokenSource = this.cancelTokenSource;
+ this.cancelTokenSource = new CancellationTokenSource();
+
+ oldTokenSource.Cancel();
+ oldTokenSource.Dispose();
}
/// <summary>