using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Threading; using log4net; using WisdomClient.data; using WisdomClient; namespace IntelligentControlForsx.MyControls.syz { public partial class ZTControl : UserControl { private ILog logger = LogManager.GetLogger("AppInfoLog"); private Dictionary dictPoint; public ZTControl() { InitializeComponent(); } private void ZTControl_Load(object sender, EventArgs e) { dictPoint = new Dictionary(); foreach (var p in this.pnlImage.Controls) { IPointData pd = p as IPointData; if (pd != null && String.IsNullOrWhiteSpace(pd.TagId) == false) { dictPoint.Add(pd.TagId, pd); } } } private void timer1_Tick(object sender, EventArgs e) { if (isLoadding == true) return; Thread ayscThread = new Thread(LoadData); ayscThread.IsBackground = true; ayscThread.Start(); } public void DeActive() { timer1.Stop(); this.Hide(); } public void Active() { this.Show(); Thread ayscThread = new Thread(LoadData); ayscThread.IsBackground = true; ayscThread.Start(); timer1.Start(); } private bool isLoadding = false; private void LoadData() { if (isLoadding == true) return; isLoadding = true; try { UpdatePnlImage(); } catch (Exception ex) { logger.Info("读取实时数据失败!ex=" + ex.Message); } finally { isLoadding = false; } } private void UpdatePnlImage() { if (dictPoint == null || dictPoint.Count < 1) return; var points = dictPoint.Keys.ToArray(); Dictionary dictResult = RestfulClient.findLatestByTagNames(points); lock (this.pnlImage) { this.BeginInvoke( (Action)delegate { for (int i = 0; i < points.Length; i++) { String tagId = points[i]; if (tagId == "NSSDQ.NX_GD_NSSF_DQ_P1_L1_001_DI0088") { TsData tt = dictResult[tagId]; Console.WriteLine("123"); } if (dictResult.ContainsKey(tagId) && dictPoint.ContainsKey(tagId)) { TsData tsData = dictResult[tagId]; IPointData pd = dictPoint[tagId]; pd.TagData = tsData; } } }); } } } }