Yeah, I probably went a little overboard with the BackgroundWorker. You were right Chris, I was in a bit of a time crunch so I just removed most of the threading code for this release. I think you might be right about the Session being closed with a BackgroundWorker thread. I have not had chance to finish reading through the links Fabio included about the async pattern but wouldn't I have the same threading issues using NH with that pattern? We decided against web services so that we could take advantage of NH change tracking as well as lazy load. I really appreciate all of the help!
Thanks, Chris On Sep 10, 3:08 pm, Fabio Maulo <[email protected]> wrote: > btw Chris...when you have a front-end issue try to maintain the solution in > the front-end without affecting the back-end. > to fill a combo using a background is not a great idea. > > 2009/9/10 Chris W <[email protected]> > > > > > > > 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 > > -- > Fabio Maulo --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
