C
C#15mo ago
Exi

✅ await in computed property?

hello, i have my blazorwasm app and a razorpage with a few checkboxes. if I check or uncheck a checkbox I want to call a function to fetch data. my component (mudblazor): <MudCheckBox @bind-Checked="@missing_column_statistics" Label="missing_column_statistics" Color="Color.Primary"> </MudCheckBox> private bool _missing_column_statistics = false; public bool missing_column_statistics { get => _missing_column_statistics; set { _missing_column_statistics = value; SearchExtendedEvents(); // he wants await here } } my SearchExtendedEvents is a async task (public async Task SearchExtendedEvents()) and because of that its crying for await but I cant just add it. I've googled a little bit and found smth like that: set { _optimizer_timeout = value; new Task(async () => { await SearchExtendedEvents(); }).Start(); } but idk if thats a good way to do it. Maybe my way of doing this is bad anyways and maybe someone can give me advice how to handle this. Thanks
3 Replies
Jimmacle
Jimmacle15mo ago
you can't have async in properties and property getters/setters shouldn't have complex logic like that anyway i would use Checked and CheckedChanged instead of two way binding
Exi
ExiOP15mo ago
would you show me an example how that would look like? just a simple one
Jimmacle
Jimmacle15mo ago
Checked="@missing_column_statistics" CheckedChanged="@TheMethodThatHandlesTheValueChanging"

Did you find this page helpful?