1
0
mirror of synced 2024-11-15 01:33:51 +00:00
PettingZoo/PettingZoo.Tapeti/UI/PackageProgress/PackageProgressWindow.xaml.cs

44 lines
1.0 KiB
C#
Raw Normal View History

using System;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
namespace PettingZoo.Tapeti.UI.PackageProgress
{
/// <summary>
/// Interaction logic for PackageProgressWindow.xaml
/// </summary>
public partial class PackageProgressWindow : IProgress<int>
{
private readonly CancellationTokenSource cancellationTokenSource = new();
public CancellationToken CancellationToken => cancellationTokenSource.Token;
public PackageProgressWindow()
{
InitializeComponent();
Closed += (_, _) =>
{
cancellationTokenSource.Cancel();
};
}
public void Report(int value)
{
Dispatcher.BeginInvoke(() =>
{
Progress.Value = value;
});
}
private void CancelButton_OnClick(object sender, RoutedEventArgs e)
{
cancellationTokenSource.Cancel();
((Button)sender).IsEnabled = false;
}
}
}