New Posts New Posts RSS Feed: Serial Coroutines and ManagedThreadId
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Serial Coroutines and ManagedThreadId

 Post Reply Post Reply
Author
stephenmcd1 View Drop Down
DevForce MVP
DevForce MVP


Joined: 27-Oct-2009
Location: Los Angeles, CA
Posts: 166
Post Options Post Options   Quote stephenmcd1 Quote  Post ReplyReply Direct Link To This Post Topic: Serial Coroutines and ManagedThreadId
    Posted: 29-Oct-2010 at 12:55pm
I've run into problems when using Serial Coroutines with respect to the ManagedThreadId property on the EntityManager.  The exception specifically says that I should "Consider calling the EntityManager’s asynchronous methods; they work safely on background threads managed by DevForce. "  I thought I was using the asynchronous methods so I was expecting it to work.  An example of the code is as follows:

        public void TestCoroutine(AsyncEventCompletedCallback<GenericAsyncEventArgs<int>> callback)
        {
            //Get the entity manager from somewhere
            var myEntityManager = Uow.EntityManager;

            Coroutine.Start(
                () => BuildBasicCoroutine(myEntityManager),
                op =>
                    {
                        //Always fails
                    });
        }

        private static IEnumerable<INotifyCompleted> BuildBasicCoroutine(DataModelEntityManager em)
        {
            yield return em.Users.ExecuteAsync();
            yield return em.Contracts.ExecuteAsync();
        }

If I switch it to use Coroutine.StartParallel it will succeed just fine but in many cases I actually need serial behavior becaues one query depends on a previous query.  

It seems like this should be possible and maybe I'm just doing something basic wrong.  Any help would be appreciated.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 29-Oct-2010 at 3:52pm
It should be possible with serial execution, and does work in our tests.
 
I can think of two reasons why you might get this error:
  • The Uow.EntityManager was constructed on another thread, or
  • You're running in a test environment (or a console application) which does free threading and doesn't synchronize threads to the context. 
Back to Top
stephenmcd1 View Drop Down
DevForce MVP
DevForce MVP


Joined: 27-Oct-2009
Location: Los Angeles, CA
Posts: 166
Post Options Post Options   Quote stephenmcd1 Quote  Post ReplyReply Direct Link To This Post Posted: 01-Nov-2010 at 8:27pm
Thanks, I was testing this in two place.  One was a unit test which we expect to fail.  The other was in a Silverlight app but I found that it was something else that was messing with my entity manager so mystery solved.  Thanks for the help.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down