initial load
This commit is contained in:
44
YouTubeViewers.WPF/Commands/AsyncCommandBase.cs
Normal file
44
YouTubeViewers.WPF/Commands/AsyncCommandBase.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace YouTubeViewers.WPF.Commands
|
||||
{
|
||||
public abstract class AsyncCommandBase : CommandBase
|
||||
{
|
||||
private bool _isExecuting;
|
||||
|
||||
public bool IsExecuting
|
||||
{
|
||||
get { return _isExecuting; }
|
||||
set { _isExecuting = value;
|
||||
OnCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanExecute(object? parameter)
|
||||
{
|
||||
return !_isExecuting && base.CanExecute(parameter);
|
||||
}
|
||||
|
||||
|
||||
public override async void Execute(object? parameter)
|
||||
{
|
||||
IsExecuting = true;
|
||||
|
||||
try
|
||||
{
|
||||
await ExecuteAsync(parameter);
|
||||
}
|
||||
catch (Exception) { }
|
||||
finally
|
||||
{
|
||||
IsExecuting = false;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract Task ExecuteAsync(object? parameter);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user