-
I would like to call aysnc methond inside the generated partial void OnPropertyChanged method, could anyone kindly let me know how to perform it? [ObservableProperty]
public partial string DbPath { get; set; } = string.Empty;
partial void OnDbPathChanged(string value)
{
Settings.Default.DbPath = DbPath;
Settings.Default.Save();
// await ReloadDbUsers();
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
You should be able to just change the signature to Since it isn't returning a Generally you would not want to use I realized I might not have answered your actual question about whether this can "work perfectly". A real MVVM library expert might be able to chime in and give a reason why my suggestion is a bad one in this case, but I don't know of any. Whether it works "perfectly" depends on what that means. The only thing I can think of that might cause problems, which I already mentioned above, is that it will be *actually asynchronous. So when If you need it to do that, then you will probably need to use some additional concurrency mechanics, like a Or, alternatively, possibly ideal, refactor this so it is done with a method in the first place instead of a property. For example, invert the flow and replace |
Beta Was this translation helpful? Give feedback.
-
@bzd3y In my app, I use to boolean IsReady to indicate the DbUser loading status, then UI use this flag to disable controls. Maybe it doesn't need awaitable at this time. I will use fire and whencomplete to finish the property changed method. Thanks for your kind reply! |
Beta Was this translation helpful? Give feedback.
You're welcome. What support are you wondering about? I think what you are trying to do is supported. You can use the
void async
like I initially suggested, IF you don't need any code after the property is set to wait for theasync
to complete.If you do, then your options are:
TaskCompletionSource
. This would still require you to await some otherTask
, so it probably doesn't buy you anything over just setting the property and then callingReloadDbUsers
manually, although it does let you easily switch between awaiting it or not.UpdateDbPathAsync()
to set the path and then callReloadDbUsers
. This is the simplest…