Cursor.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //------------------------------------------------------------------------------
  2. // <copyright file="MessageEnumerator.cs" company="Microsoft">
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. // </copyright>
  5. //------------------------------------------------------------------------------
  6. using Experimental.System.Messaging.Interop;
  7. using System;
  8. namespace Experimental.System.Messaging
  9. {
  10. public sealed class Cursor : IDisposable
  11. {
  12. private CursorHandle handle;
  13. private bool disposed;
  14. internal Cursor(MessageQueue queue)
  15. {
  16. CursorHandle result;
  17. int status = SafeNativeMethods.MQCreateCursor(queue.MQInfo.ReadHandle, out result);
  18. if (MessageQueue.IsFatalError(status))
  19. throw new MessageQueueException(status);
  20. this.handle = result;
  21. }
  22. internal CursorHandle Handle
  23. {
  24. get
  25. {
  26. if (disposed)
  27. {
  28. throw new ObjectDisposedException(GetType().Name);
  29. }
  30. return handle;
  31. }
  32. }
  33. public void Close()
  34. {
  35. if (handle != null)
  36. {
  37. handle.Close();
  38. handle = null;
  39. }
  40. }
  41. public void Dispose()
  42. {
  43. this.Close();
  44. this.disposed = true;
  45. }
  46. }
  47. }