Here is a first very naive approach, without MVVM
private async void ButtonStartClick(object sender, RoutedEventArgs e)
{
myButton.IsEnabled = false;
await RunTask();
myButton.IsEnabled = true;
}
where RunTask is declared like this:
private async Task RunTask()
{
// await some other awaitable method(s)
}
If you have a long running task that isn't awaitable, you may run it by Task.Run
like this:
private async Task RunTask()
{
await Task.Run(() =>
{
// do somthing here
});
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…