EventWaitHandle.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. using System.Runtime.InteropServices;
  33. namespace System.Threading
  34. {
  35. [ComVisible (true)]
  36. public class EventWaitHandle : WaitHandle
  37. {
  38. private EventWaitHandle (IntPtr handle)
  39. {
  40. Handle = handle;
  41. }
  42. public EventWaitHandle (bool initialState, EventResetMode mode)
  43. {
  44. bool created;
  45. Handle = NativeEventCalls.CreateEvent_internal ((mode == EventResetMode.ManualReset), initialState, null, out created);
  46. }
  47. public EventWaitHandle (bool initialState, EventResetMode mode,
  48. string name)
  49. {
  50. bool created;
  51. Handle = NativeEventCalls.CreateEvent_internal ((mode == EventResetMode.ManualReset), initialState, name, out created);
  52. }
  53. public EventWaitHandle (bool initialState, EventResetMode mode,
  54. string name, out bool createdNew)
  55. {
  56. Handle = NativeEventCalls.CreateEvent_internal ((mode == EventResetMode.ManualReset), initialState, name, out createdNew);
  57. }
  58. [MonoTODO ("Implement access control")]
  59. public EventWaitHandle (bool initialState, EventResetMode mode,
  60. string name, out bool createdNew,
  61. EventWaitHandleSecurity eventSecurity)
  62. {
  63. Handle = NativeEventCalls.CreateEvent_internal ((mode == EventResetMode.ManualReset), initialState, name, out createdNew);
  64. }
  65. [MonoTODO]
  66. public EventWaitHandleSecurity GetAccessControl ()
  67. {
  68. throw new NotImplementedException ();
  69. }
  70. public static EventWaitHandle OpenExisting (string name)
  71. {
  72. return(OpenExisting (name, EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify));
  73. }
  74. public static EventWaitHandle OpenExisting (string name, EventWaitHandleRights rights)
  75. {
  76. if (name == null) {
  77. throw new ArgumentNullException ("name");
  78. }
  79. if ((name.Length == 0) ||
  80. (name.Length > 260)) {
  81. throw new ArgumentException ("name", Locale.GetText ("Invalid length [1-260]."));
  82. }
  83. MonoIOError error;
  84. IntPtr handle = NativeEventCalls.OpenEvent_internal (name, rights, out error);
  85. if (handle == (IntPtr)null) {
  86. if (error == MonoIOError.ERROR_FILE_NOT_FOUND) {
  87. throw new WaitHandleCannotBeOpenedException (Locale.GetText ("Named Event handle does not exist: ") + name);
  88. } else if (error == MonoIOError.ERROR_ACCESS_DENIED) {
  89. throw new UnauthorizedAccessException ();
  90. } else {
  91. throw new IOException (Locale.GetText ("Win32 IO error: ") + error.ToString ());
  92. }
  93. }
  94. return(new EventWaitHandle (handle));
  95. }
  96. public bool Reset ()
  97. {
  98. CheckDisposed ();
  99. return (NativeEventCalls.ResetEvent_internal (Handle));
  100. }
  101. public bool Set ()
  102. {
  103. CheckDisposed ();
  104. return (NativeEventCalls.SetEvent_internal (Handle));
  105. }
  106. [MonoTODO]
  107. public void SetAccessControl (EventWaitHandleSecurity eventSecurity)
  108. {
  109. throw new NotImplementedException ();
  110. }
  111. }
  112. }
  113. #endif