CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

WinRT factory method example using async/await

rated by 0 users
Answered (Verified) This post has 1 verified answer | 3 Replies | 2 Followers

Top 50 Contributor
178 Posts
Tim posted on Thu, Jul 5 2012 8:33 AM

Could someone provide an example of where the async/await capabilities fit into an object's public factory methods in WinRT?   From what I have read, I can still do it the old way:

public static void BeginFetchMyList(EventHandler<DataPortalResult<MyInfoList>> callback)
{
  var portal = new DataPortal<MyInfoList>();
  portal.FetchCompleted += callback;
  portal.BeginFetch();
}

But I'd like to take advantage of the async/await features in v4.5.  I did see a recent thread about using async in the DP_XYZ method, but not sure how that fits into the public factory methods.  Thanks.

Tim

Answered (Verified) Verified Answer

Top 10 Contributor
9,270 Posts
Verified by Tim

Yes, the old way continues to work (backward compatibility is important).

The new way is relatively straightforward, and is in the new cslafact snippet.

public static async Task<MyInfoList> FetchMyListAsync()
{
  return await DataPortal.FetchAsync<MyInfoList>();
}

Fwiw, there's a static helper for the old way too, so your existing code could be:

public static void BeginFetchMyList(EventHandler<DataPortalResult<MyInfoList>> callback)
{
  DataPortal.BeginFetch<MyInfoList>(callback);
}

This new async/await support is in the current pre-release, so you can use this now. The async/await support for DataPortal_XYZ will be in the next pre-release (soon).

Rocky

All Replies

Top 10 Contributor
9,270 Posts
Verified by Tim

Yes, the old way continues to work (backward compatibility is important).

The new way is relatively straightforward, and is in the new cslafact snippet.

public static async Task<MyInfoList> FetchMyListAsync()
{
  return await DataPortal.FetchAsync<MyInfoList>();
}

Fwiw, there's a static helper for the old way too, so your existing code could be:

public static void BeginFetchMyList(EventHandler<DataPortalResult<MyInfoList>> callback)
{
  DataPortal.BeginFetch<MyInfoList>(callback);
}

This new async/await support is in the current pre-release, so you can use this now. The async/await support for DataPortal_XYZ will be in the next pre-release (soon).

Rocky

Top 50 Contributor
178 Posts
Tim replied on Thu, Jul 5 2012 9:48 AM

Thank you for the example.  So does my DP_XYZ methods also need to include the await keyword when executing a DAL method?  Or at that point, since its already being executed asyncronously can I leave that to be the same as I have always done?

Tim

Top 10 Contributor
9,270 Posts

In the current pre-release you can not (easily) use async/await concepts in DataPortal_XYZ.

In the next pre-release you will be able to use async/await concepts in DataPortal_XYZ.

Using await on the client-side data portal is entirely independent of using it in the server-side data portal. You can mix and match.

Rocky

Page 1 of 1 (4 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems