Multiple fetches at same time are not async

Multiple fetches at same time are not async

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


jhardman posted on Wednesday, June 12, 2013

I have come across a problem I am trying to load up multiple business objects to display in the UI.  The first call is performed on a background thread but the other calls are on the UI thread.  Once this occurs all subsequent calls are on the UI thread.  e.g. to keep this simple I am fetching the same BO twice but in reality they are difference BO's.

            Settings.BeginGetSettings((o, e) => { });

            System.Threading.Thread.Sleep(1000);

            Settings.BeginGetSettings((o, e) => { });

 

    [Serializable]

    public class Settings : BusinessBase<Settings>

    {

        public static readonly Csla.PropertyInfo<string> WebServiceUrlProperty = RegisterProperty<string>(c => c.WebServiceUrl);

 

        public string WebServiceUrl

        {

            get { return ReadProperty(WebServiceUrlProperty); }

            set { SetProperty(WebServiceUrlProperty, value); }

        }

 

        public static void BeginGetSettings(EventHandler<Csla.DataPortalResult<Settings>> callback)

        {

            Csla.DataPortal.BeginFetch<Settings>(callback);

        }

        private void DataPortal_Fetch()

        {

            System.Threading.Thread.Sleep(5000);

        }

    }

If you put a breakpoint in DataPortal_Fetch() you will see the first time it is on a background thread and the second time it is on the main/UI thread.

This issue is caused by setting ApplicationContext.LogicalExecutionLocation to Server in Csla.Server.DataPortal.  The second call now reads it as Server in Csla.DataPortalClient.LocalProxy resulting in a synchronous call.  To make things worst the second call records _oldLocation as Server in Csla.Server.DataPortal since the first call has changed it.  Therefore when the second call completes it sets ApplicationContext.LogicalExecutionLocation to Server and now all calls will be synchronous.

I do not know the ins and outs of LocalProxy, DataPortal and how ApplicationContext.LogicalExecutionLocation is meant to work and hence I am cautious of making changes.  I suspect Server is important when using remoting which I am not.  I can also see that Server is used if a BO makes a call to another BO in the DataPortal_XYZ methods then it would be synchronous which is a good thing.

Any ideas on how to fix this issue?

Copyright (c) Marimer LLC