コード例 #1
0
        private void Apiform_OnHIDNum(int CardNumber)
        {
            Thread thread = new Thread(() =>
            {
                try
                {
                    string strCardNo = CardNumber.ToString();
                    if (CardNumber < 0)
                    {
                        string str = CardNumber.ToString("x8").PadLeft(8);
                        strCardNo  = long.Parse(str, System.Globalization.NumberStyles.HexNumber).ToString();
                    }
                    if (strCardNo.Length < 3)
                    {
                        return;
                    }
                    short errorFlag = new MenJinService().GetOpenResult(strCardNo, this.IP);
                    if (errorFlag == 1)
                    {
                        apiform.PlayVoiceByIndex(10);
                    }
                    else if (errorFlag == 2)
                    {
                        apiform.PlayVoiceByIndex(10);
                        apiform.ACUnlock(MachineNumber, 200);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Writer.Write(ex);
                }
            });

            thread.IsBackground = true;
            thread.Start();
        }
コード例 #2
0
 public void RunReloadMachine()
 {
     try
     {
         List <MachinesEntity> machines = null;
         if (_OPCode == 0)
         {
             lock (lockobj)
             {
                 try
                 {
                     if (_OPCode != 0)
                     {
                         return;
                     }
                     CanRun(false);
                     machines     = new MenJinService().GetEnableMachinesEntitys().OrderBy(t => t.MachineNumber).ToList();
                     this._OPCode = machines.Count;
                 }
                 catch (Exception ex)
                 {
                     this._OPCode = 0;
                     throw ex;
                 }
                 if (this._OPCode == 0)
                 {
                     return;
                 }
             }
         }
         else
         {
             return;
         }
         for (int i = 0; i < 35; i++)
         {
             string key = string.Format("{0}{1}", ctlName, (i + 1));
             var    ctl = this.Controls[key] as AppContainer;
             ctl.RunStopMachine();
         }
         int machinescount = machines.Count;
         for (int i = 0; i < 35; i++)
         {
             string key = string.Format("{0}{1}", ctlName, (i + 1));
             var    ctl = this.Controls[key] as AppContainer;
             if (i <= (machinescount - 1))
             {
                 ctl.Machine = machines[i];
                 Thread thread = new Thread(new ParameterizedThreadStart(StartMachine));
                 thread.IsBackground = true;
                 thread.Start(ctl);
             }
         }
     }
     catch (Exception ex)
     {
         //Logger.Writer.Write(ex);
         //Thread.Sleep(10000);
         //RunReloadMachine();
         throw ex;//如果数据库连接不上交由应用程序异常处理,重启
     }
 }