Async execution

Posts   
 
    
Padgett
User
Posts: 30
Joined: 09-Oct-2003
# Posted on: 10-Oct-2005 08:22:27   

Hello,

Does any one have an example of retrieving data from the self servicing sprocs, views or entities asyncronously?

Cheers,

Padgett

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 10-Oct-2005 17:08:34   

What exactly do you mean with asynchronically? Call GetMulti() or FetchEntityCollection() and return immediately, and get an event when the data is available?

Frans Bouma | Lead developer LLBLGen Pro
Padgett
User
Posts: 30
Joined: 09-Oct-2003
# Posted on: 10-Oct-2005 19:16:24   

Hi Otis,

Yes - That would be ideal.

padgett

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 11-Oct-2005 20:31:08   

That's not supported at the moment. All calls are synchronous. There are also no plans to build this into the application in the near future.

The main reason is that you can easily build it yourself: create a thread, do the fetching in there and report back when the data is fetched.

Frans Bouma | Lead developer LLBLGen Pro
Padgett
User
Posts: 30
Joined: 09-Oct-2003
# Posted on: 12-Oct-2005 07:22:38   

Hi Otis,

Sorry - i wasn't asking for this to be built into the framework, I was wasking for an example on how to do what you just described - ie. load the data on a sperate thread then report back when it was done.

Cheers,

Padgett

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 12-Oct-2005 10:30:28   

Padgett wrote:

Hi Otis,

Sorry - i wasn't asking for this to be built into the framework, I was wasking for an example on how to do what you just described - ie. load the data on a sperate thread then report back when it was done.

Oh, sorry about that simple_smile

Key for properly doing this is setting up a way to communicate back to the main thread the data is there. I'd do that with a delegate object, which is passed to the new thread and which is p/invoked (no direct call, call Invoke). The delegate is called with the data to fetch as parameter. You can also decide to keep a volatile member variable around where the data is fetched into but that's error prone.

So, - create delegate to method in mainthread which is used by fetch thread to report data is available. Delegate has to have parameter which is the collection to fetch - create fetch thread from main thread. Execution of Fetch thread starts - fetch thread does normal fetching, for example a lot of entity objects using a FetchEntityCollection - fetch code ends, so thread is effectively done. - Fetch thread calls delegate, passing in the collection with data to fetch, which is a reference to the entity collection - main thread's method is called, it receives the data. As it is called using Invoke, the method is ran through the mainthread, and it can safely store the reference to the entity collection in a variable and work with it. - fetch thread is now completely done and simply ends (routine is exited)

Frans Bouma | Lead developer LLBLGen Pro