EventWaitHandle.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // System.Threading.EventWaitHandle.cs
  3. //
  4. // Author:
  5. // Dick Porter ([email protected])
  6. //
  7. // (C) Ximian, Inc. (http://www.ximian.com)
  8. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_2_0
  30. using System.Security.AccessControl;
  31. using System.IO;
  32. namespace System.Threading
  33. {
  34. public class EventWaitHandle : WaitHandle
  35. {
  36. private EventWaitHandle (IntPtr handle)
  37. {
  38. Handle = handle;
  39. }
  40. public EventWaitHandle (bool initialState, EventResetMode mode)
  41. {
  42. bool created;
  43. Handle = NativeEventCalls.CreateEvent_internal ((mode == EventResetMode.ManualReset), initialState, null, out created);
  44. }
  45. public EventWaitHandle (bool initialState, EventResetMode mode,
  46. string name)
  47. {
  48. bool created;
  49. Handle = NativeEventCalls.CreateEvent_internal ((mode == EventResetMode.ManualReset), initialState, name, out created);
  50. }
  51. public EventWaitHandle (bool initialState, EventResetMode mode,
  52. string name, out bool createdNew)
  53. {
  54. Handle = NativeEventCalls.CreateEvent_internal ((mode == EventResetMode.ManualReset), initialState, name, out createdNew);
  55. }
  56. [MonoTODO ("Implement access control")]
  57. public EventWaitHandle (bool initialState, EventResetMode mode,
  58. string name, out bool createdNew,
  59. EventWaitHandleSecurity eventSecurity)
  60. {
  61. Handle = NativeEventCalls.CreateEvent_internal ((mode == EventResetMode.ManualReset), initialState, name, out createdNew);
  62. }
  63. [MonoTODO]
  64. public EventWaitHandleSecurity GetAccessControl ()
  65. {
  66. throw new NotImplementedException ();
  67. }
  68. public static EventWaitHandle OpenExisting (string name)
  69. {
  70. return(OpenExisting (name, EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify));
  71. }
  72. public static EventWaitHandle OpenExisting (string name, EventWaitHandleRights rights)
  73. {
  74. if (name == null) {
  75. throw new ArgumentNullException ("name");
  76. }
  77. if ((name.Length == 0) ||
  78. (name.Length > 260)) {
  79. throw new ArgumentException ("name", Locale.GetText ("Invalid length [1-260]."));
  80. }
  81. MonoIOError error;
  82. IntPtr handle = NativeEventCalls.OpenEvent_internal (name, rights, out error);
  83. if (handle == (IntPtr)null) {
  84. if (error == MonoIOError.ERROR_FILE_NOT_FOUND) {
  85. throw new WaitHandleCannotBeOpenedException (Locale.GetText ("Named Event handle does not exist: ") + name);
  86. } else if (error == MonoIOError.ERROR_ACCESS_DENIED) {
  87. throw new UnauthorizedAccessException ();
  88. } else {
  89. throw new IOException (Locale.GetText ("Win32 IO error: ") + error.ToString ());
  90. }
  91. }
  92. return(new EventWaitHandle (handle));
  93. }
  94. public bool Reset ()
  95. {
  96. CheckDisposed ();
  97. return (NativeEventCalls.ResetEvent_internal (Handle));
  98. }
  99. public bool Set ()
  100. {
  101. CheckDisposed ();
  102. return (NativeEventCalls.SetEvent_internal (Handle));
  103. }
  104. [MonoTODO]
  105. public void SetAccessControl (EventWaitHandleSecurity eventSecurity)
  106. {
  107. throw new NotImplementedException ();
  108. }
  109. }
  110. }
  111. #endif