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