QMonWorkerContext.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Net.Sockets;
  2. using Quadarax.Foundation.Core.Object;
  3. using Quadarax.Foundation.Core.Thread;
  4. namespace Quadarax.Foundation.Core.QMonitor
  5. {
  6. public class QMonWorkerContext : DisposableObject, IWorkerContext
  7. {
  8. #region *** Fields ***
  9. private UdpClient? _udpClient;
  10. #endregion
  11. #region *** Properties ***
  12. public UdpClient Client => _udpClient ?? throw new InvalidOperationException("UDP client channel is not open (is null).");
  13. #endregion
  14. #region *** Constructors ***
  15. public QMonWorkerContext(UdpClient? udpClient)
  16. {
  17. SetClient(udpClient);
  18. }
  19. #endregion
  20. #region *** Public Operations ***
  21. public void SetClient(UdpClient? udpClient)
  22. {
  23. _udpClient = udpClient;
  24. }
  25. #endregion
  26. #region *** Protected Operations ***
  27. protected override void OnDisposing()
  28. {
  29. Client?.Close();
  30. Client?.Dispose();
  31. SetClient(null);
  32. }
  33. #endregion
  34. }
  35. }