MVVM: Asynchronous Commands

The latest cut of the Apex Code (http://apex.codeplex.com/SourceControl/changeset/changes/6701) contains a very cool new feature – Asynchronous Command Objects.

An Asynchronous Command is a ViewModelCommand – the standard object used in Apex for commanding. However, what is different about this function is that it runs Asynchronously.

One of the problems with running a view model command asynchronously is that generally the view model properties cannot be accessed – as they’re created on a different dispatcher. This problem is resolved by using the ‘ReportProgress’ function. Here’s an example:

public class SomeViewModel : ViewModel
  public SomeViewModel()
     // Create the command.
     asyncCommand = new AsynchronousCommand(DoAsyncCommand, true);

  private void DoAsyncCommand()
     for(int i = 0; i < 100; i++)
        // Perform some long operation.
        string message = DoSomeLongOperation();

        // Add the message to the View Model - safely!
          () =>
  private ObservableCollection<string> messages =
    new ObservableCollection<string>();

  public ObservableCollection<string> Messages
     get { return messages; }

  private AsynchronousCommand asyncCommand;

  public AsynchronousCommand AsyncCommand
     get { return asyncCommand; }

In this basic mock-up we have a command called ‘AsyncCommand’ (which we could bind a button to for example) which invokes DoAsyncCommand. However, it invokes it Asynchronously. We can also update the ViewModel properties by using ReportProgress – meaning AsyncCommands can seamlessly provide live feedback while they’re working – and we’re keeping well locked in with the MVVM commanding model!

Expect a full article soon on the CodeProject, until then the source is at:



SharpGL 2.0 Beta 1 Released

It’s been a long time coming, but the first Beta of SharpGL 2.0 is finally here!

The Beta is on CodePlex at: http://sharpgl.codeplex.com/releases/view/74704

This includes the binaries, example applications and full source code.

Some of the more exciting features are:

  • Full hardware acceleration
  • OpenGL Extensions
  • Full core functionality up to OpenGL 4.2
  • Native WPF Control
Below is a screenshot of SharpGL in a WPF application:
And here’s a link to a new CodeProject article describing how to use SharpGL in a WPF application:
Please try out SharpGL 2.0 Beta 1 and let me know what you think!

CodeProject Competition

My Solitaire and Spider Solitaire in WPF article is in two CodeProject competitions this month. The article is at:


If you think the article is worthy of a vote, then please go to the voting page for either of the two competitions!

Best C# Article: http://www.codeproject.com/script/Surveys/VoteForm.aspx?srvid=1209

Best Overall Article: http://www.codeproject.com/script/Surveys/VoteForm.aspx?srvid=1212