Async and Multithreading Considerations
Exceptions may be thrown if plots are modified in one thread while another thread is performing a render. To prevent race conditions like this, lock the Plot.Sync object to prevent rendering while potentially dangerous operations are performed.
System.Timers.Timer Timer = new() { Interval = 10; Enabled = true; };
Timer.Elapsed += (s, e) =>
{
lock (plotControl.Plot.Sync)
{
// Operations inside this block will not start
// until the previous render is finished, and the next
// render will not start until these operations complete.
ChangeDataLength();
}
// Request a redraw (which may occur in another thread)
WpfPlot1.Refresh();
};
WPF Demo: A sample application demonstrating multi-threaded plot updates in WPF is available in the WPF demo project.