I have a class with RefreshAsync method which can take a long time to execute. I am using Mvvm light framework. I need to call it after object created but not everytime when I get it's instance from servicelocator
var vm = ServiceLocator.Current.GetInstance<FileSystemViewModel>();
So I use DispatcherTimer
to create deferred update logic. But it does not fire and I don't know why.
Here is the code
private DispatcherTimer _timer;
public FileSystemViewModel()
{
_timer = new DispatcherTimer(DispatcherPriority.Send) {Interval = TimeSpan.FromMilliseconds(20)};
_timer.Tick += DefferedUpdate;
_timer.Start();
}
private async void DefferedUpdate(object sender, EventArgs e)
{
(sender as DispatcherTimer)?.Stop();
await RefreshAsync().ConfigureAwait(false);
}