2 // System.Threading.EventWaitHandle.cs
5 // Dick Porter (dick@ximian.com)
7 // (C) Ximian, Inc. (http://www.ximian.com)
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
32 using System.Security.AccessControl;
35 namespace System.Threading
37 public class EventWaitHandle : WaitHandle
39 private EventWaitHandle (IntPtr handle)
44 public EventWaitHandle (bool initialState, EventResetMode mode)
48 Handle = NativeEventCalls.CreateEvent_internal ((mode == EventResetMode.ManualReset), initialState, null, out created);
51 public EventWaitHandle (bool initialState, EventResetMode mode,
56 Handle = NativeEventCalls.CreateEvent_internal ((mode == EventResetMode.ManualReset), initialState, name, out created);
59 public EventWaitHandle (bool initialState, EventResetMode mode,
60 string name, out bool createdNew)
62 Handle = NativeEventCalls.CreateEvent_internal ((mode == EventResetMode.ManualReset), initialState, name, out createdNew);
65 [MonoTODO ("Implement access control")]
66 public EventWaitHandle (bool initialState, EventResetMode mode,
67 string name, out bool createdNew,
68 EventWaitHandleSecurity eventSecurity)
70 Handle = NativeEventCalls.CreateEvent_internal ((mode == EventResetMode.ManualReset), initialState, name, out createdNew);
74 public EventWaitHandleSecurity GetAccessControl ()
76 throw new NotImplementedException ();
79 public static EventWaitHandle OpenExisting (string name)
81 return(OpenExisting (name, EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify));
84 public static EventWaitHandle OpenExisting (string name, EventWaitHandleRights rights)
87 throw new ArgumentNullException ("name");
89 if ((name.Length == 0) ||
90 (name.Length > 260)) {
91 throw new ArgumentException ("name", Locale.GetText ("Invalid length [1-260]."));
95 IntPtr handle = NativeEventCalls.OpenEvent_internal (name, rights, out error);
96 if (handle == (IntPtr)null) {
97 if (error == MonoIOError.ERROR_FILE_NOT_FOUND) {
98 throw new WaitHandleCannotBeOpenedException (Locale.GetText ("Named Event handle does not exist: ") + name);
99 } else if (error == MonoIOError.ERROR_ACCESS_DENIED) {
100 throw new UnauthorizedAccessException ();
102 throw new IOException (Locale.GetText ("Win32 IO error: ") + error.ToString ());
106 return(new EventWaitHandle (handle));
113 return (NativeEventCalls.ResetEvent_internal (Handle));
120 return (NativeEventCalls.SetEvent_internal (Handle));
124 public void SetAccessControl (EventWaitHandleSecurity eventSecurity)
126 throw new NotImplementedException ();