Command Objects executed with BeginExecute are not Async (4.5.24-RC)

Command Objects executed with BeginExecute are not Async (4.5.24-RC)

Old forum URL: forums.lhotka.net/forums/t/11962.aspx


BenBoneyIII posted on Monday, April 29, 2013

I am using the DataPortal_Execute methods in my command objects.  I call them from the Command's Factory Method:

DataPortal.BeginExecute(Of MyCommandObj)(cmd, callback)

I call the Factory Methods from a ViewModel (WPF) using a Lambda expression for the callback.

The code never runs as Async.

I am not sure if this is a bug or if I don't know what I am doing, but if I change this code in the DataPortalT.cs in CSLA, it works:

This code change is in the BeginExecute(T command, object userState) method.

 var result = await DoUpdateAsync(command, false);   *** I changed the isSync parameter value to False ***

 

Am I on the right track here?

Thanks for your help.

Ben

RockfordLhotka replied on Monday, April 29, 2013

That does look like a bug. I think the code should actually look like this:

    public async void BeginExecute(T command, object userState)
    {
      try
      {
        var result = await UpdateAsync(command);
        OnExecuteCompleted(new DataPortalResult<T>(result, null, userState));
      }

The same bug is in BeginUpdate too.

BenBoneyIII replied on Tuesday, April 30, 2013

Rocky,

I changed the BeginExecute as you suggested and that worked great!

Thanks,

Ben

RockfordLhotka replied on Tuesday, April 30, 2013

Great! I appreciate your help!

Copyright (c) Marimer LLC