Skip to content

Instantly share code, notes, and snippets.

@julesx
Created July 31, 2014 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julesx/0cd80e7dfb8c38daaf37 to your computer and use it in GitHub Desktop.
Save julesx/0cd80e7dfb8c38daaf37 to your computer and use it in GitHub Desktop.
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using WpfApplication30.Annotations;
namespace WpfApplication30
{
public partial class MainWindow : INotifyPropertyChanged
{
private bool _doingWork;
public MainWindow()
{
InitializeComponent();
DataContext = this;
}
public bool DoingWork
{
get { return _doingWork; }
set
{
_doingWork = value;
OnPropertyChanged("DoingWork");
}
}
public void ButtonClicked(object o)
{
DoingWork = true;
Task.Factory.StartNew(delegate
{
//Look at me doing some work, going to take about 15 seconds
Thread.Sleep(15000);
}).ContinueWith(t =>
{
DoingWork = false;
});
}
private RelayCommand _buttonClicked;
public ICommand CmdButtonClicked { get { return _buttonClicked ?? (_buttonClicked = new RelayCommand(ButtonClicked)); } }
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment