Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Thread safe use of graph

Hi,

 

I am using the FixedSizeIntensityChartCollection code from M21097 . Normally I use callback to the UI thread when updating, but wants to use a lock instead. Not sure if this is possible, but have tried the following without success.

 

I have extended class with IEnumerable

 

public sealed class FixedSizeIntensityChartCollection<TZ> : IGraphDataCollection, IEnumerable<NationalInstruments.Controls.Data.Sample<ulong,TZ>>

 

I then use EnableCollectionSynchronization :

 

WaterfallData = new FixedSizeIntensityChartCollection<double>(generalConfig.numberOfFrequencyLinesOnlineWaterfallPlot, generalConfig.numberOfTimeLinesOnlineWaterfallPlot, deltaT);

_lock = new object();

BindingOperations.EnableCollectionSynchronization(WaterfallData, _lock);

 

And when updating on the thread I use the lock:

 

lock (_lock)
{

   WaterfallData.Append(specter);
}

 

The problem is that this is not working as it seems the lock is not working. Is it done wrong or is it not possible? The error messsaege from the debugger:

 

image.png

 

0 Kudos
Message 1 of 3
(922 Views)

The WPF graph requires data updates to occur on the UI thread.  Using an external lock to synchronize writing of the data will not help, because the graph has no way to use that lock when reading the data to ensure it gets a consistent view.

 

To support multi-threaded asynchronous updates, you would need to create a custom data store that dispatches update notifications to the UI thread, and requests from the graph would need to be provided a full copy of the data that will not change while the graph is processing it.

 

Alternatively, instead of locking when performing data updates, you can dispatch the updates to the UI thread, using something along the lines of:

graph.Dispatcher.BeginInvoke(new Action<IList<double>>(WaterfallData.Append), specter);
~ Paul H
0 Kudos
Message 2 of 3
(898 Views)

Thanks for quick reply. Yes, the dispatch solution is the one I am using now. The reason why I started looking into this is that I have a data heavy application with four graphs. Running on a physcal computer with GPU this is no problem. But when running on a virtual server with no GPU I start to get lag on the graphs. I was hoping locking could improve it, but probably wouldn't help anything. Too bad having a lot of processors, but no way to take advatage of them :-). I guess the best solution is to get a graphics card with GPU for ther server?

 

Oddvar

0 Kudos
Message 3 of 3
(873 Views)