Calling DataPortal inside DataPortal.Fetch -> new thread?

Calling DataPortal inside DataPortal.Fetch -> new thread?

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


mesh posted on Thursday, July 07, 2011

When calling DataPortal.Fetch inside another Fetch method (server side, Silverlight app), application is skipping to a new thread and User ( application have an unauthenticated principal ) and LocalContext are being lost?

EDIT: I am calling async dataportal from server side. Ok, so I cant do that and keep User object?

Thanks

RockfordLhotka replied on Thursday, July 07, 2011

You really shouldn't use async data portal calls when you are in logical server-side code. In other words, if you are "in the data portal", don't make async data portal calls.

CSLA and the data portal do absolutely nothing to ensure that such a thing would work. And this means you would need to implement thread syncronization and notification yourself.

Most notably, the "primary data portal thread" - the first one running in the logical server-side - can't be allowed to complete and return to the client until all other server-side threads complete. You are completely responsible for ensuring that is done right if you try to do async in the logical server.

You must also understand that SL itself switches all WCF (or other) async callbacks to run on the UI thread. So you also must completely understand how SL does threading.

To my knowledge, if you were really, really careful and completely understood what was going on with threading in SL and the data portal, you should be able to use async code within the server-side data portal code. But understand that CSLA doesn't do anything to support such a scenario, and I don't recommend it.

Copyright (c) Marimer LLC