I study WPF and, accordingly, MVVM pattern.

Now I am writing a program as a workout. The program takes data from a user-selected file, converts it and outputs it to a DataTable . To clear the DataTable I assign the property to which the ItemsSource table is attached, null and call OnPropertyChanged .

So the question is, is it possible to frequently call this method, how will it affect performance? For example, I have 5 different tables and when processing each file they need to be cleared from the results of the previous file. As I said, I clear by assigning a null property.

Maybe there is another way to update the contents of DataTable ( taking into account the MVVM pattern )?

  • Do you see a performance drop? One OnPropertyChanged per table is very small. - VladD
  • @VladD, once again I will explain: I call OnPropertyChanged two times in the button command for 5 tables twice. The first time to clear the tables from the previous data and the second to fill with new ones. No, I did not notice the performance drawdown, however, I am concerned about the question whether I am doing the cleaning correctly? And will it cause a drop in performance if I perform similar actions for 15 tables, for example? - badc0de32

1 answer 1

By itself, sending a PropertyChanged event is no problem. As long as you do not send these events hundreds at a time, you should not wait for a performance drawdown: sending a dozen messages and updating a dozen bindings is a quick process.

Much more time is taken by the complete redrawing of the table: after all, to draw each of the elements, it is necessary to obtain data from many references, and the number of these elements is equal to the number of rows of the table! But this is not a problem of NotifyPropertyChanged as such, it is a problem of your program design. (For example, perhaps you need a virtual list ( VirtualizingPanel.IsVirtualizing="True" ).) Or maybe this will not be a problem, nothing can be said without profiling.

Therefore:

  • Do not bother with sending a pair of miserable PropertyChanged checks.
  • But see if a huge amount of data “in one piece” does not come to UI by chance.
  • Profile, profile and profile again.