Example #1
0
        public void AddInfoLog(string title, string content)
        {
            string msg = "【" + title + "】" + content;

            LogsQueue.Enqueue(msg);
            string logMsg = String.Format("{{0}} {1}", Times.GetDateNow(), msg);
        }
Example #2
0
        // 【线程函数】数据库写入数据的线程
        private void LogThreadMethod()
        {
            Thread.Sleep(3000);
            while (true)
            {
                if (LogsQueue.Count != 0)
                {
                    try
                    {
                        string logstring = LogsQueue.Dequeue();
                        Logger.WriteLog_info(typeof(Form1), logstring);
                        bool scroll = false;

                        MessageListControl.Invoke(new Action(() =>
                        {
                            #region 写入到测试窗口
                            int FullIndex = MessageListControl.ItemHeight == 0 ?
                                            0 :
                                            MessageListControl.Items.Count - (int)(MessageListControl.Height / MessageListControl.ItemHeight);

                            if (MessageListControl.TopIndex == FullIndex)
                            {
                                scroll = true;
                            }
                            MessageListControl.Items.Add(string.Format("[{0}]-{1}", Times.GetDateNow(), logstring));
                            if (scroll)
                            {
                                MessageListControl.TopIndex = FullIndex;
                            }
                            if (MessageListControl.Items.Count > log_length)
                            {
                                MessageListControl.Items.Clear();
                            }
                            #endregion
                        }));
                    }
                    catch { }
                }
                Thread.Sleep(25);
            }
        }
 private void ReceiveCarNumber(string msg)
 {
     if (CacheTable.Rows.Count <= CachedCarsCount)
     {
         AddInfoLog("还未收到条形码,车号为:" + msg);
         return;
     }
     CarCacheGrid.Invoke(new Action(() =>
     {
         CacheTable.Rows[CachedCarsCount][0] = msg;
         AddInfoLog("收到车号:" + msg);
         var row      = CacheTable.Rows[CachedCarsCount];
         string carId = row[0].ToString();
         string code  = row[1].ToString();
         //string weight = row[2].ToString();
         string resultMsg = String.Format("[C{0}]{1}", carId, code);
         try
         {
             tcpClient.SendMsg(resultMsg);
             AddInfoLog(string.Format("发送给服务器数据=>车号:{0},条形码:{1}", carId, code));
         }
         catch (Exception ex)
         {
             AddErrorLog("发送到供包结果到TCP服务器失败:" + resultMsg, ex);
         }
         CarInfoGrid.Invoke(new Action(() =>
         {
             InfoTable.Rows.Add(new Object[] {
                 CachedCarsCount.ToString().PadLeft(4, '0'),
                 Times.GetDateNow(),
                 carId,
                 code
                 //weight
             });
         }));
         CachedCarsCount++;
     }));
 }