Major upgrade
This commit is contained in:
@@ -17,8 +17,7 @@ UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Net.Sockets;
|
||||
using Raytheon.Instruments;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
@@ -35,6 +34,7 @@ namespace Raytheon.Instruments
|
||||
private AutoResetEvent _quitEvent;
|
||||
private byte[] _dataRead;
|
||||
private readonly uint _timeToRestBetweenReadsInMs;
|
||||
private readonly ILogger _logger;
|
||||
#endregion
|
||||
|
||||
#region PublicFuctions
|
||||
@@ -48,6 +48,7 @@ namespace Raytheon.Instruments
|
||||
/// <param name="timeToRestBetweenReadsInMs">Number of ms to rest after a read call</param>
|
||||
public CommReadWorker(ICommDevice commNode, MsgDevice msghandler, uint bufferSize, uint timeToRestBetweenReadsInMs)
|
||||
{
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
_commNode = commNode;
|
||||
_threadQuitControl = false;
|
||||
_msgHandler = msghandler;
|
||||
@@ -69,23 +70,9 @@ namespace Raytheon.Instruments
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
Dispose(true);
|
||||
Dispose(true);
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
try
|
||||
{
|
||||
ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//Do not rethrow. Exception from error logger that has already been garbage collected
|
||||
}
|
||||
}
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -110,33 +97,14 @@ namespace Raytheon.Instruments
|
||||
// not using timeToRestBetweenReadsInMs. Just going to wait 1 ms and get back to the read
|
||||
if (_quitEvent.WaitOne(1))
|
||||
{
|
||||
ErrorLogger.Instance().Write("CommReadWorker::DoWork() - received signal to quit", ErrorLogger.LogLevel.INFO);
|
||||
_logger.Debug("received signal to quit");
|
||||
_threadQuitControl = true;
|
||||
}
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
if (e.SocketErrorCode == SocketError.TimedOut)
|
||||
{
|
||||
//expected
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorLogger.Instance().Write("CommReadWorker::DoWork() - " + e.Message, ErrorLogger.LogLevel.ERROR);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorLogger.Instance().Write("CommReadWorker::DoWork() - " + e.Message, ErrorLogger.LogLevel.ERROR);
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
ErrorLogger.Instance().Write("CommReadWorker::DoWork() - exiting", ErrorLogger.LogLevel.INFO);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -154,23 +122,9 @@ namespace Raytheon.Instruments
|
||||
/// <param name="disposing"></param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
if (disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_quitEvent.Dispose();
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
try
|
||||
{
|
||||
ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//Do not rethrow. Exception from error logger that has already been garbage collected
|
||||
}
|
||||
_quitEvent.Dispose();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user