Answer the question
In order to leave comments, you need to log in
Why is the View not updated when a property in the viewmodel is updated?
Inside the ViewModel, an asynchronous block is executed.
Before this block, the value of the ControlsEnabled property changes to false, inside this block it changes back to True.
More or less like this:
private void DoTheThing(string clientType)
{
var applicationWorker = new ApplicationWorker();
applicationWorker.StatusUpdated += (sender, s) =>
{
_syncContext.Post(o => StatusText = s, null); // обновление статуса в статусбаре
};
ControlsEnabled = false; // отключаем контролсы
Task.Run(() =>
{
var result = applicationWorker.DoTheThing();
_syncContext.Post(o => ControlsEnabled = true, null); // включаем контролсы (выполнение в потоке UI)
ResetDataToDefaults();
}).ContinueWith((t) =>
{
if (t.IsFaulted) SendFaultLog(t.Exception);
}, TaskScheduler.FromCurrentSynchronizationContext()); ;
}
ControlsEnabled = true
does not work. At the same time, it is clear that it ResetDataToDefaults
works (the fields on the form are cleared, although they remain "disabled"). _syncContext
i get in constructor like this: _syncContext = SynchronizationContext.Current
Application.Current.Dispatcher.Invoke(delegate { ... })
applicationWorker.DoTheThing
). The first status was shown (and occasionally one from the middle) and that's it. When I changed to _syncContext
, everything began to work like clockwork. ApplicationWorker
is in a different assembly ResetDataToDefaults
running on the UI thread. And yet, it works. So the problem is ? _syncContext.Post
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question