Posts

Showing posts from December, 2017

How to use Parallel.For in a progress bar in WPF

Image
This post shows how performance improvements are obtainable by replacing the use of a traditional 'for' loop with Parallel.For , part of the Task Parallel Library (TPL) . Step 1: Create a new Visual Studio WPF application Step 2: Add event handling classes These are classes to enable us to bind a command of a button for example. To do this you need to bind a property that is an implementation of an ICommand. RelayCommand.cs [code language="csharp"] using System; using System.Windows.Input; namespace Progress { public class RelayCommand<T> : ICommand { private readonly Predicate<T> _canExecute; private readonly Action<T> _execute; public RelayCommand(Action<T> execute) : this(execute, null) { _execute = execute; } public RelayCommand(Action<T> execute, Predicate<T> canExecute) { if (execute == null) throw new ArgumentNullEx...