Csla 4.1: "Objects that are marked busy may not be saved" should be more forgiving?

Csla 4.1: "Objects that are marked busy may not be saved" should be more forgiving?

Old forum URL: forums.lhotka.net/forums/t/10156.aspx


JCardina posted on Thursday, March 10, 2011

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?

ajj3085 replied on Thursday, March 10, 2011

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.

JCardina replied on Thursday, March 10, 2011

Just throwing it out there. :)

mosgath replied on Friday, March 11, 2011

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();

JCardina replied on Friday, March 11, 2011

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.

g.beraudo@castsoftware.com replied on Tuesday, February 26, 2013

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