Beispiel #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            UI = new IOInterface();
            th = new Thread(RunUI);
            th.SetApartmentState(ApartmentState.STA);
            th.Start();
            Thread th1 = new Thread(SaveFile);

            th1.SetApartmentState(ApartmentState.STA);
            th1.IsBackground = true;
            //th1.Start();
        }
        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();
        }
Beispiel #3
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;
                }
            }
        }