S
S
Sergey Tsatsatsa2018-08-02 17:36:57
WPF
Sergey Tsatsatsa, 2018-08-02 17:36:57

NotifyPropertyChanged - what went wrong?

There is a GUI application (DevExpress, WPF, C#) based on MVVM, which was written by me and worked, the bindings in the controls worked and there were no problems with them. But suddenly, something was updated or something fell off or the stars did not converge, but the bindings stopped working adequately.
I'll try to describe the problem.
There is a Count property of some class that implements the INotifyPropertyChanged interface.
There is a TextBlock that displays the value of this property using Binding.
There is button number 1, which, using ICommand, asynchronously starts the procedure for scanning a folder on a disk. In the process, a small analysis of files and a count of the number occur with the corresponding increment of the Count property, which in turn sends a PropertyChanged event. The whole procedure happens asynchronously in Task.
There is another button #2 created for the test, which, when clicked, simply increments this Count property from the main thread.
When performing this sequence of actions, something happens that I cannot understand:

  1. Press button No. 2 (as many times as you like) - Count is incremented, TextBlock is updated and displays the current value of Count
  2. Next, press the button number 1 - the update does not occur. That is, events fly away somewhere or get stuck along the way.
  3. Next, press button No. 2 again - Count is incremented, TextBlock is not updated now . That is, the events disappear somewhere.

What I tried to solve:
  • When running the application on another machine, the problem recurs
  • After reinstalling VisualStudio and DevExpress, the problem persists
  • Raised a separate virtual machine with VS and DevExpress, built the application there, but the problem was not solved

There is a suspicion that the thread dispatching these events is suspended (frozen), but the rest of the controls, besides this TextBlock, work .... or the PropertyDescriptor is confused.
Another nuance: I added tracing to the application using TraceSource, SourceSwith and other similar tools. But I do not want to believe that this is the problem, and the problem remains in the Release build mode.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Yudakov, 2018-08-02
@AlexanderYudakov

I would use Dispatcher.BeginInvoke() to increment Count from a background thread.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question