Luke
Luke

Reputation: 2486

WPF - Listview updating very sporadic

I have a WPF program with two listviews which display information from two different observable collections. These observable collections are updated on a timer which fires every second.

For some reason, these listviews do not update when the data collection is updated... they will update occasionally but there is no guarantee that it will ever happen. I can run the whole program for 10 minutes and have nothing displayed... There are no databinding errors in the output window, either. In fact, if I populate the collection during startup, to test the binding, it is all displayed without problems. It's only when I am adding items dynamically during the execution of the program that there is a problem.

When trying to debug it is impossible to follow the program because for some reason I've got a whole load of worker threads running which I never defined or asked for:

https://i.sstatic.net/Z0XB3.png

I think these extra threads might be part of the problem. Is there an easy way in C# to define a function as threadsafe like the synchronized keyword in Java?

EDIT:

JFifoErrorCollection.Add(errorData); 
JFifoList.Items.Refresh(); 
break; 

EDIT #2: I have solved this issue.. I was using a System.Threading.Timer which didn't run on the UI thread. Changed to System.Windows.Forms.Timer and now it works perfectly.

Upvotes: 3

Views: 506

Answers (1)

Tri Q Tran
Tri Q Tran

Reputation: 5690

Use the WPF built in DispatcherTimer.

Upvotes: 1

Related Questions