private static void ACSQuery() { foreach (ControllerListSource cls in IODataCollection.queryList.Where(c => c.name.StartsWith("ACS-"))) { string queryStr = ACSQueryUtilities.GenACSSimQueryStr(cls.IOList); acsu.BeginTransaction(cls.name, queryStr, new AsyncCallback(OnTransaction), acsu); RunningTransaction.Add(cls.name); } }
private static void OnTransaction(IAsyncResult ar) { object[] os = (object[])ar.AsyncState; string cname = (string)os[0]; ACSControllerUtilities _acsu = (ACSControllerUtilities)os[1]; string queryStr = ACSQueryUtilities.GenACSSimQueryStr(IODataCollection.queryList.Find(cls => cls.name == cname).IOList); try { string transStr = _acsu.EndTransaction(ar); List <int> tl = ACSQueryUtilities.ConvertACSTransStr(transStr, out bool result); if (!result) { string err = $"变量名错误或未定义:{cname}@{queryStr}=>{transStr}"; IOInterface.updateError = true; RunningTransaction.Remove(cname); IOInterface.ShowError(err); return; } IODataCollection.UpdateIOQueryList(cname, tl); if (!ACSThreadAbort) { Thread.Sleep(50); _acsu.BeginTransaction(cname, queryStr, new AsyncCallback(OnTransaction), _acsu); } else { RunningTransaction.Remove(cname); if (RunningTransaction.Count == 0) { ACSThreadAborted = true; } } } catch (Exception e) { string err = $"{e.Message}:{cname}@{queryStr}"; IOInterface.updateError = true; RunningTransaction.Remove(cname); if (RunningTransaction.Count == 0) { ACSThreadAborted = true; } IOInterface.ShowError(err); } GC.Collect(); }