UOW, Multi-Threading, and Refetching

Posts   
 
    
JRR avatar
JRR
User
Posts: 125
Joined: 07-Dec-2005
# Posted on: 24-Jul-2007 20:35:48   

Hello, this is a general question. I have not started coding this scenario yet, but want to understand this first.

  • Modify Entities
  • Add Entities to UOW.AddForSave(refetch = True)
  • Pass UOW on to Worker Thread
  • Worker thread opens connection
  • UOW is Committed.. and here is my question:

How do the refetched entities make their way back to the main thread? Does it happen automatically, or do I need to pass them back in code?

Thanks!

mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 25-Jul-2007 09:47:16   

JRR wrote:

Hello, this is a general question. I have not started coding this scenario yet, but want to understand this first.

  • Modify Entities
  • Add Entities to UOW.AddForSave(refetch = True)
  • Pass UOW on to Worker Thread
  • Worker thread opens connection
  • UOW is Committed.. and here is my question:

How do the refetched entities make their way back to the main thread? Does it happen automatically, or do I need to pass them back in code?

Ehm, entities (and objects in general) don't belong to any thread and thus they don't travel between the threads at all. That said the only thing you have to worry about is concurrency. If you refetech (or modify) your entity in non UI thread you have to pay attention that it doesn't affect UI in any way (general Windows rule - non UI thread must not affect UI). And you have to synhcronize access in case other threads are working with entities being refetched, too.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 25-Jul-2007 11:47:00   

How do the refetched entities make their way back to the main thread? Does it happen automatically, or do I need to pass them back in code?

Either pass them back in code. Or refetch them from the database in the original thread.

JRR avatar
JRR
User
Posts: 125
Joined: 07-Dec-2005
# Posted on: 25-Jul-2007 17:39:24   

Thanks guys. simple_smile

I am looking for a generic way to add entities to a uow, committing it on a worker thread, and then pass the entities(refetched) back to the ui thread.

It's the last part I am wrestling with here, do you have any rough examples?

My UOW will have several entities and collections, so I am trying to avoid refetching each one individually.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 26-Jul-2007 10:51:14   

and then pass the entities(refetched) back to the ui thread.

I guess you can add a callback function in the original thread, so it can be called from the worker thread when it finishes commiting the UoW, and the UoW can be passed as a parameter to the call back function.