I'm trying to execute a command so that a function I have runs asynchronously in from within the constructor of my view. I understand that running something asynchronously in a constructor isn't necessarily good practice, but I need to load a datagrid when the view opens which takes anywhere from 3-5 seconds, so I thought I could load a progress bar with an IsLoading
property while my command to fetch the data runs on a separate thread.
Here is my command / property declaration to do the above:
public ReactiveCommand EnterCmd { get; private set; }
ObservableAsPropertyHelper<bool> _isLoading;
public bool IsLoading => _isLoading.Value;
And here are my instantiations in the constructor:
EnterCmd = ReactiveCommand.CreateFromTask(LoadGridData);
EnterCmd.IsExecuting.ToProperty(this, x => x.IsLoading, out _isLoading);
I'd like to run start my command by doing something like EnterCmd.Execute()
.
It's worth noting that I did find a similar question here, but Execute()
doesn't seem to be a valid method on a ReactiveCommand
anymore. Any ideas would be appreciated.
Unit
? I can't seem to find solid documentation on it. – Brahmi