public void RefreshData() { if (RefreshScheduled) { return; } bool workedBefore = false; while (IsWorking) { RefreshScheduled = true; Debug.WriteLine("Waiting for cancelation"); CancellationTokenSource.Cancel(); Thread.Sleep(100); workedBefore = true; } IsWorking = true; RefreshScheduled = false; if (HistoryItems.Any() && !workedBefore) { GetDataFromTfs(HistoryItems.Max(x => x.ChangeSetId), Int32.MaxValue); } else { GetDataFromTfs(null, Int32.MaxValue, true); } IsWorking = false; }