using DIT.SharedMemory; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace SHARP_CLAS_UI { public class Alarm_Occurred_Manager:IDisposable { #region Property private static readonly Lazy _instatnce = new Lazy(() => new Alarm_Occurred_Manager()); public static Alarm_Occurred_Manager Instance { get { return _instatnce.Value; } } public List Alarm_Occured_List { get; private set; } public bool Is_Heavy { get; private set; } #endregion #region Filed SharedMemory sm; byte[] Current_Data; bool IsDisposed; Thread Data_Update_Th; #endregion #region Construct private Alarm_Occurred_Manager() { IsDisposed = false; Is_Heavy = false; sm = new SharedMemory("SHARP_CLAS", 10000, true); sm.Open(); Alarm_Occured_List = new List(); Alarm_Occured_List.Clear(); Data_Update_Th = new Thread(Data_Update_Th_Set); Data_Update_Th.Start(); } #endregion #region Function public void Dispose() { IsDisposed = true; } private void Data_Update_Th_Set() { while (!IsDisposed) { Thread.Sleep(10); DateTime dt = DateTime.Now; Data_Update(); TimeSpan ts = (DateTime.Now - dt); } } private void Data_Update() { try { DateTime dt = DateTime.Now; bool heavycheck = false; SharedmemoryAddressInfo[] Alarm_List = Alarm_Memory_Address.Get_Address_Infos(); for (int i = 0; i < Alarm_List.Length; i++) { object value = 0; if (sm.Get_Value(Alarm_List[i], out value)) { if ((bool)value) { Alarm info; if (Alarm_Manager.Instance.Get_Alarm_Info(i, out info)) { if (info.Use) continue; if (info.Heavy) heavycheck = true; if (!Alarm_Occured_List.Exists(x => x.CODE == (int)info.Code)) { Alarm_Occured_List.Add(new AlarmOccurredInfo((int)info.Code, info.Code.ToString(), info.Description, info.Heavy)); } } } } } Is_Heavy = heavycheck; TimeSpan ts = DateTime.Now - dt; } catch (Exception) { } } #endregion } }