private void processIncomingMessages()
        {
            while (!m_exit || m_incomingMessages.Count > 0)
            {
                try
                {
                    if (m_waitingSemaphore.Wait(1000))
                    {
                        MessageContentAndInfo message;
                        lock (m_incomingMessages)
                        {
                            message = m_incomingMessages.Dequeue();
                        }
                        m_messages.Add(message);

                        if (m_messages.Count > m_messageBufferLength)
                        {
                            m_messages.RemoveAt(0);
                        }

                        OnNewMessageReceived(message);
                    }
                }
                catch (Exception exp)
                {
                    MessageContentAndInfo message = new MessageContentAndInfo("processIncomingMessages:" + exp.Message);
                    OnNewMessageReceived(message);
                }
            }
        }
示例#2
0
        void gOnly_NewMessageReceived(object sender, MessageContentAndInfo args)
        {
            ListViewItem newMsg = new ListViewItem(args.MessageTime.ToString("HH:mm:ss.fff"));

            newMsg.SubItems.Add(new ListViewItem.ListViewSubItem(newMsg, args.Message));

            if (args.MessageType == MessageType.Alarm)
            {
                newMsg.BackColor = Color.Red;
            }
            else if (args.MessageType == MessageType.Warning)
            {
                newMsg.BackColor = Color.Yellow;
            }
            else if (args.MessageType == MessageType.Info)
            {
                newMsg.BackColor = Color.White;
            }
            else if (args.MessageType == MessageType.OK)
            {
                newMsg.BackColor = Color.Lime;
            }
            else if (args.MessageType == MessageType.NG)
            {
                newMsg.BackColor = Color.DarkRed;
            }
            lock (newMessages)
            {
                newMessages.Add(newMsg);
            }
        }
        private void OnNewMessageReceived(MessageContentAndInfo message)
        {
            // Copy the delegate for thread safety
            NewMessageReceivedEventHandler handlers = NewMessageReceived;

            if (handlers != null)
            {
                handlers(this, message);
            }
        }
示例#4
0
 void gOnly_NewMessageReceived(object sender, MessageContentAndInfo args)
 {
     lock (m_lockObject)
     {
         if (DateTime.Now > m_currentLogFileExpirationTime || m_currentLogFile == null)
         {
             CreateNewLogFile();
         }
         if (m_currentLogFile != null)
         {
             m_currentLogFile.WriteLine("{0}\t{1}\t{2}", args.MessageTime.ToString("yyyyMMdd_HH:mm:ss"), args.MessageType.ToString(), args.Message);
         }
     }
 }
示例#5
0
 public void WriteToLogFileSynchronous(MessageContentAndInfo message)
 {
     gOnly_NewMessageReceived(null, message);
 }