How to properly wait for _all_ rules to be finished? (Sync and Async) #3751
Unanswered
ossendorf-at-hoelscher
asked this question in
Questions
Replies: 2 comments 11 replies
-
Are you using |
Beta Was this translation helpful? Give feedback.
5 replies
-
This console app confirms that all rules (property change and checkrules) complete before the data portal returns from the logical server. using Csla;
using Csla.Configuration;
using Csla.Rules;
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.AddCsla();
var serviceProvider = services.BuildServiceProvider();
var portal = serviceProvider.GetRequiredService<IDataPortal<MyBusinessObject>>();
var obj = await portal.FetchAsync();
Console.WriteLine(obj.Data);
[Serializable]
public class MyBusinessObject : BusinessBase<MyBusinessObject>
{
public static readonly PropertyInfo<string> DataProperty = RegisterProperty<string>(c => c.Data);
public string Data
{
get { return GetProperty(DataProperty); }
set { SetProperty(DataProperty, value); }
}
protected override void AddBusinessRules()
{
base.AddBusinessRules();
BusinessRules.AddRule(new MyRule { PrimaryProperty = DataProperty });
}
[Fetch]
private async Task Fetch()
{
Data = "Fetched";
await BusinessRules.CheckRulesAsync();
Console.WriteLine("Fetch completed");
}
}
public class MyRule : BusinessRuleAsync
{
protected override async Task ExecuteAsync(IRuleContext context)
{
await Task.Delay(5000);
Console.WriteLine("Rule executed");
}
} This is without |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We are currently having issues with our asp.net core host which keeps crashing because async rules are still running while CSLA is moving from the server to the client.
This results in the same exceptions as in #3490 described.
So what's currently the correct way/approach to wait on an object to have finished all running rules?
I tried the
ValidationComplete
but that's no good. It's raised two times. One time for the sync rules to have finished and a second time for the async one. Since I can't know if ever a second raise will come or not that's not a reliable way of telling.Should I use the IsBusy here? Is that safe?
Beta Was this translation helpful? Give feedback.
All reactions