I guess you have a web app. The problem is that the
SessionFactoryHolder stores the created session in the HttpContext,
which the thread doesn't have access to. You can try (without any
warranty) HybridThreadScopeInfo instead of WebThreadScopeInfo.
The better idea is to use conversations:
Create a runner class that keeps a ScopedConversation and calls the
methods in a ConversationalScope or by using the IConversations
Execute() method. This way you have each thread running with its own
independent session.

-Markus

2010/8/12 Mike Christensen <[email protected]>:
> Hi guys -
>
> I have three very hefty functions that load data from the DB, but can
> run independently of each other.  I run them like this:
>
> LoadRecipeGraph();
> LoadIngredientGraph();
> LoadRatingGraph();
>
> This works great, no errors.  Since they all take several seconds
> each, I'd like to run them in parallel.  So I'm trying this:
>
> Thread recipeLoader = new Thread(LoadRecipeGraph);
> Thread ingLoader = new Thread(LoadIngredientGraph);
> Thread ratingLoader = new Thread(LoadRatingGraph);
>
> recipeLoader.Start();
> ingLoader.Start();
> ratingLoader.Start();
>
> recipeLoader.Join();
> ingLoader.Join();
> ratingLoader.Join();
>
> The first one starts, with no errors.  However, when I call Start on
> the second one, I immediately get:
>
> "WebThreadScopeInfo: Could not access HttpContext.Current"
> on the line:
>
> ISession session = holder.CreateSession(typeof(DB.User));
>
> Each function is pretty much the same, it loads data from a view like this:
>
> ISessionFactoryHolder holder = ActiveRecordMediator.GetSessionFactoryHolder();
> ISession session = holder.CreateSession(typeof(DB.User)); <-- Crash here
> IDbCommand cmd = session.Connection.CreateCommand();
> cmd.CommandType = CommandType.TableDirect;
> cmd.CommandText = "SomeDBView";
> IDataReader reader = cmd.ExecuteReader();
>
> while (reader.Read())
> {
>   //Do a bunch of junk
> }
>
> What am I doing wrong?  Thanks!!
>
> Mike
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Castle Project Users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/castle-project-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to