/// <summary>
        /// 添加通道
        /// </summary>
        /// <param name="channelNo">通道号码</param>
        public void AddChannel(string channelLabel)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);

            try
            {
                bool successed = this.channelDicLocker.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME);
                // 申请互斥
                if (successed)
                {
                    try
                    {
                        MonitorChannel channel = new MonitorChannel(channelLabel, this.softTerminalAdapter);
                        if (!this.monitorChannelDic.ContainsKey(channelLabel))
                        {
                            this.monitorChannelDic.Add(channelLabel, channel);
                        }

                        logEx.Trace("Add Channel channelNo:{0}", channelLabel);
                    }
                    finally
                    {
                        // 释放互斥量
                        this.channelDicLocker.ExitWriteLock();
                    }
                }
                else
                {
                    // 日志
                    logEx.Error("AddChannel: Enert Write Lock Failed.WaitingReadCount:{0};WaitingWriteCount:{1}.", this.channelDicLocker.WaitingReadCount, this.channelDicLocker.WaitingWriteCount);
                }
            }
            catch (Exception ex)
            {
                // 日志
                logEx.Error(ex, "AddChannel: Enert Write Lock Exception.");
            }
        }
Beispiel #2
0
        /// <summary>
        /// 添加通道
        /// </summary>
        /// <param name="channelNo">通道号码</param>
        public void AddChannel(string channelLabel)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);

            try
            {
                bool successed = this.channelDicLocker.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME);
                // 申请互斥
                if (successed)
                {
                    try
                    {
                        MonitorChannel channel = new MonitorChannel(channelLabel, this.softTerminalAdapter);
                        if (!this.monitorChannelDic.ContainsKey(channelLabel))
                        {
                            this.monitorChannelDic.Add(channelLabel, channel);
                        }

                        logEx.Trace("Add Channel channelNo:{0}", channelLabel);
                    }
                    finally
                    {
                        // 释放互斥量
                        this.channelDicLocker.ExitWriteLock();
                    }
                }
                else
                {
                    // 日志
                    logEx.Error("AddChannel: Enert Write Lock Failed.WaitingReadCount:{0};WaitingWriteCount:{1}.", this.channelDicLocker.WaitingReadCount, this.channelDicLocker.WaitingWriteCount);
                }
            }
            catch (Exception ex)
            {
                // 日志
                logEx.Error(ex, "AddChannel: Enert Write Lock Exception.");
            }
        }