Multithreading is tricky stuff and I don't really recommend the approach you
are going with here.  I have a similar problem in a program I am working on
but I used messaging as an approach.  The UI layer (ViewModel specifically)
sends and receives messages which are handled by services that can query or
update the database.

The allows you to achieve certain goals easily like, multithreading (use
asyncronous message queues) as well as command query separation if desired.

I sense you are probably looking for a more immediate solution the problem
at the moment though.  If I had to hazard a guess, from your error I would
say you are grabbing a static session that is not thread safe and then
closing it in one thread while another is still using it.

That said you need to post the code your BackgroundWorker is actually
calling to query/update through nHibernate and the code you are using to
manage sessions.

Chris



On Thu, Sep 10, 2009 at 1:14 PM, Chris W <[email protected]>wrote:

>
> Hello,
>
> I am looking for a little advice.  I am creating a WPF application and
> am having trouble figuring out how to implement a functional threading
> approach.  I have been creating a new instance of BackgroundWorker and
> using that when making calls to NH.  I have basically been relying on
> the UI thread not making any calls to NH when these BackgroundWorker
> threads are processing.  This approach seemed to have been working
> until recently.  Now that I am getting into more complex views I am
> running into error every so often.  I tried searching online to see
> how other are handling this type of thing but have not had much luck.
> I am getting error like "Invalid attempt to call Read when reader is
> closed." and "Invalid operation. The connection is closed." which seem
> to be a result of this weak approach.  This is my first project using
> both WPF and NH, so I am a little wet behind the ears.  Below is an
> example of how I am using the BackgroundWorker.
>
>        public BackgroundWorker Worker { get; set; }
>
>        private void GetSubCategoryList()
>        {
>            var entity = view.CurrentEntity.PartSubcategory;
>            var partcategory = view.CurrentEntity.PartCategory;
>            if (partcategory == null)
>                view.SubcategoryList = null;
>            else
>            {
>                Worker = new BackgroundWorker();
>                Worker.DoWork += delegate(object sender,
> DoWorkEventArgs e)
>                {
>                    e.Result =
> Globals.BLL.PartSubcategory.GetAllForCombo(null, partcategory);
>                };
>
>                Worker.RunWorkerCompleted += delegate(object sender,
> RunWorkerCompletedEventArgs e)
>                {
>                    if (!ErrorHandler.Process(this, e.Error))
>                    {
>                        view.SubcategoryList = e.Result as
> List<PartSubcategory>;
>                    }
>                };
>                Worker.RunWorkerAsync();
>            }
>        }
>
> Thanks,
> Chris
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" 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/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to