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();
        }
Exemplo n.º 2
0
        private static void Update(string cname, List <string> queryList)
        {
            while (true)
            {
                try
                {
                    Thread.Sleep(50);
                    List <int> tl = LSu.ReadDevice(cname, queryList);
                    IODataCollection.UpdateIOQueryList(cname, tl);
                }
                catch (Exception e)
                {
                    string queryStr = string.Join(",", queryList);
                    string err      = $"{e.Message} {cname}@{queryStr}";
                    IOInterface.updateError = true;
                    RunningTransaction.Remove(cname);
                    if (RunningTransaction.Count == 0)
                    {
                        LSThreadAborted = true;
                    }

                    IOInterface.ShowError(err);
                    return;
                }

                if (LSThreadAbort)
                {
                    RunningTransaction.Remove(cname);
                    if (RunningTransaction.Count == 0)
                    {
                        LSThreadAborted = true;
                    }
                    return;
                }
            }
        }