confused over async and sync ebooks and sample code

confused over async and sync ebooks and sample code

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


griff posted on Friday, June 03, 2011

Hi

I have e-books (csla creating and data access) alos downloadedd code DataAccess sample code.

In sample code below I am confused by the code in bold - is this not Async code and should come under the #if SILVERLIGHT directive?  An error in the book/code sample of my understanding?

My understanding is that anything BeginCreate, BeginFetch etc is SL (async) and the rest DataPortal.Create/Fetch etc is Sync.

Thanks. Richard

 

#if SILVERLIGHT
    public static void NewOrderEdit(int customerId, EventHandler<DataPortalResult<OrderEdit>> callback)
    {
      DataPortal.BeginCreate<OrderEdit>(customerId, callback, DataPortal.ProxyModes.LocalOnly);
    }
 
    protected void DataPortal_Create(int customerId, Csla.DataPortalClient.LocalProxy<OrderEdit>.CompletedHandler handler)
    {
      using (BypassPropertyChecks)
      {
        Id = -1;
        CustomerId = customerId;
        OrderDate = DateTime.Today;
        LastEdit = DateTime.Today;
      }
      OrderLineItems = DataPortal.CreateChild<OrderLineItems>();
      base.DataPortal_Create(handler);
    }
#else
    public static void NewOrderEdit(int customerId, EventHandler<DataPortalResult<OrderEdit>> callback)
    {
      DataPortal.BeginCreate<OrderEdit>(customerId, callback);
    }
 
    public static OrderEdit NewOrderEdit(int customerId)
    {
      return DataPortal.Create<OrderEdit>(customerId);
    }
 
    public static OrderEdit GetOrderEdit(int id)
    {
      return DataPortal.Fetch<OrderEdit>(id);
    }

 

griff replied on Friday, June 03, 2011

Bold hasn't  worked so it's this code in the if !SILVERLIGHT code area:

 

 public static void NewOrderEdit(int customerId, EventHandler<DataPortalResult<OrderEdit>> callback)
    {
      DataPortal.BeginCreate<OrderEdit>(customerId, callback);
    }

RockfordLhotka replied on Friday, June 03, 2011

I generally write the async factory methods so they are available to .NET and SL code. The sync factory methods are only available to .NET code, because they can't work in SL.

In that example I think I was showing how to use RunLocal on .NET, and the equivalent (but different) technique on SL - and so the async factory is implemented differently for SL and .NET.

I use async factories on .NET a lot - specifically in WPF apps. In fact, I pretty much only use the sync factory methods in web apps or servce apps.

griff replied on Friday, June 03, 2011

 

So my understanding is correct then?  The examples show that you choose to call async methods outside of Silverlight environment e.g. .Net /WPF for example .

I think it makes sense now.

Thanks

 

 

Copyright (c) Marimer LLC