using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace RealTimeGraphEx.Synchronization { public class SyncManager { protected Thread pushThread; internal List Graphs { get; set; } public bool IsStarted { get; private set; } public int RefreshRate { get; set; } public SyncManager() { Graphs = new List(); RefreshRate = 30; } public void AddGraph(RealTimeGraphExBase graph) { if (!Graphs.Contains(graph)) { graph.IsSynced = true; Graphs.Add(graph); } } public void RemoveGraph(RealTimeGraphExBase graph) { graph.IsSynced = false; Graphs.Remove(graph); } public void Start() { if (!IsStarted) { IsStarted = true; pushThread = new Thread(PushThreadMethod); pushThread.IsBackground = true; pushThread.Start(); } } public void Stop() { IsStarted = false; } public void PushThreadMethod() { while (IsStarted) { Graphs.ForEach(x => x.OnRenderGraph()); Thread.Sleep(RefreshRate); } } } }