I am implementing a asp mvc application and I need to save a user business object that has a unique name.
I've implemented the unique business rule using a CommandBase class (like CheckUserName).
When I try bos.Save() I get "Can't save object that is busy".
I can do the following while(bos.IsBusy); bos.Save() and it works, but I am sure there is someone here that does is much better.
Any ideas ?
It is usually best to avoid using async rules or the async data portal when building non-interactive apps (like ASP.NET, workflow, etc).
If you do want to use async behaviors, then you'll need to do async programming, there is no way around that.
The best way to do async programming with rules is to handle the ValidationComplete event - that's when you know all the rules are done. Use something like a ManualResetEvent object to block the main thread until validation is complete.
Using a while loop is a bad idea - that's a busy loop and will waste resources.
Thank you for your answer.
I gave up on the while loop, like you said is not a bright idea, instead I've made a static Check metod in my command that calls the Execute syncronus on the dataportal. This means I removed the rule, but it works ok. What do you think ?
Took a look a the ptracker mvc in the contrib sources and couldn't find a decent implementation there also.
Maybe you will include a decent implementation of this problem in some examples, as I see you've took a lot of interest in asp mvc with the latest release.
Copyright (c) Marimer LLC