Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7005829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:24:02+00:00 2026-05-27T21:24:02+00:00

All, I have looked through source of Castle Active Record project (in .net) in

  • 0

All,

I have looked through source of Castle Active Record project (in .net) in the area of conversations and conversational scope. I have concluded that the conversations in active record cannot span different threads. In other words, when I create conversation on thread A and than try to use ConversationalScope (using current conversation created on thread A) on thread B where I access for example a lazy collection on an instance that was loaded on thread A I will get an exception because the SesessionFactoryHolder that checks the current thread scope will not find any registered scopes for thread B because thread scopes (in windows forms) are stored per thread (thread static field).

Is the above understanding correct? If yes, is that not limiting? Conversations should be able to span different threads. If that’s true, I would like to ask for some ideas how to share a hibernate session (using Castle Active Record) across multiple threads without writing a lot of code.

EDIT: I would like to add to this post past on my latest finding. The above statement that a conversation does not span threads still holds true. The statement in regards to not being able to load lazy collections on another thread is false. Lazy collections CAN be loaded lazily on another thread (in this example on thread B). The reason for this as I discovered is that as long a the conversation lives, so do the sessions, and therefore lazy collections can be accessed.

EDIT 2: I figured it out. I will leave my old post with this answer so others who have questions about this topic can benefit.

ANSWER: In castle active record framework conversations can be shared across threads. What happens is that on a new thread a session scope is always registered with the following line:

ConversationalScope scope = new ConversationalScope(currConv)

Therefore, the current thread has a valid session scope. The SessionFactoryHolder is then forced to use the current session scope for the thread (instead of using its local session). The logic for retrieving hibernate session is that it delegates this task to the conversation which will return the last hibernate session (created on previous thread A). Hence, you get the same session that was created by another thread provided the conversation scope is valid (not disposed).

Here’s the example code:

Thread A:

IScopeConversation conv = new ScopedConversation();
var order = null;

using (ConversationalScope scope = new ConversationalScope(conv))
{
  order = Order.Load(1);
}

// spawn/run thread B, access lazy collection on order

Thread B:

using (ConversationalScope scope = new ConversationalScope(conv))
{
 IList orderDetails = order.Details;  // will NOT cause exception since the conversation is still valid (has not been disposed)
}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:24:02+00:00Added an answer on May 27, 2026 at 9:24 pm

    In castle active record framework conversations can be shared across threads. What happens is that on a new thread a session scope is always registered with the following line:

    ConversationalScope scope = new ConversationalScope(currConv)

    Therefore, the current thread has a valid session scope. The SessionFactoryHolder is then forced to use the current session scope for the thread (instead of using its local session). The logic for retrieving hibernate session is that it delegates this task to the conversation which will return the last hibernate session (created on previous thread A). Hence, you get the same session that was created by another thread provided the conversation scope is valid (not disposed).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have looked all over and cannot figure out why this code isn't working.
I have looked all over the web and cannot find exactly what I am
I have looked all around and only found solutions for python 2.6 and earlier,
I have looked all over the web and I can not find the information
Every place I have looked all I can find is how to read a
I have looked on the web to find a list of all Python keywords
OK I have looked and searched all i want to do is fire a
I have looked everywhere for help on this. I'm new to all this and
I have looked at the usual suspects...Spark, NHaml, etc. They all seem to be
Okay, I have looked hard for this answer, but all the websites, even the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.