Should the BusinessBase Save() method have some sort of forgiveness of a brief duration for saving a busy object?
I ask because in my unit tests I often run into this exception as a result of an async business rule not quite completed yet when save is called.
It's just a unit test but there are often requirements in code to programmatically work with the business object library (during an import for example) and it's trivially easy to forget to add something like this every time:
System.Threading.SpinWait.SpinUntil(() => !NewUnit.IsBusy, 2000);
Is there any value in some configurable way to pad saves with some forgiveness?
I wouldn't think this is something that should be built in, but I imagine you could create an extension method that does this, something like SaveWhenNotBusy.
Just throwing it out there. :)
For us, we don't allow the save to be called until the objects are no longer busy. For the unit test, I had to use the following to delay the save:
if (myobject.IsBusy) { System.Threading.AutoResetEvent wait = new System.Threading.AutoResetEvent(false); myobject.BusyChanged += (p, f) => { if (!myobject.IsBusy) wait.Set(); }; wait.WaitOne(); } myobject = myobject.Save();
Wow Matt, the SpinWait.SpinUntil is a *lot* less code plus you get a timeout you can set, see my first post in this thread.
Hello,
I have faced the same issue with CSLA 4.5.11, I do not solve the problem with your solution .
Unfortunately, my problem is not inside the test code :(
I have created a distinct thread: http://forums.lhotka.net/forums/p/11854/54959.aspx
as the CSLA version is distinct and I use AsyncTargettingPack on .NET4
Gilles
Copyright (c) Marimer LLC