예제 #1
0
 private void InitFields()
 {
     try {
         _RxlDataSet = new RxlDataSet();
         _SingleLock = new Dictionary <string, EventWaitHandle>();
         foreach (DataTable table in _RxlDataSet.Tables)
         {
             bool            createdNew = false;
             string          handleName = string.Format("{0}{1}Lock", DefaultApplicationInfo.AbbreviatedApplicationName, table.TableName);
             EventWaitHandle waitHandle = null;
             try {
                 waitHandle = EventWaitHandle.OpenExisting(handleName, EventWaitHandleRights.FullControl);
             } catch { }
             if (waitHandle == null)
             {
                 EventWaitHandleSecurity waitHandleSecurity = new EventWaitHandleSecurity();
                 waitHandleSecurity.SetAccessRule(new EventWaitHandleAccessRule(@"BUILTIN\Administrators", EventWaitHandleRights.FullControl, AccessControlType.Allow));
                 waitHandle = new EventWaitHandle(true, EventResetMode.AutoReset, handleName, out createdNew, waitHandleSecurity);
             }
             _SingleLock.Add(table.TableName, waitHandle);
         }
     } catch {
         throw;
     }
 }
예제 #2
0
파일: source.cs 프로젝트: ruo2012/samples-1
    public static void Main()
    {
        // Create a string representing the current user.
        string user = Environment.UserDomainName + "\\" +
                      Environment.UserName;

        // Create a security object that grants no access.
        EventWaitHandleSecurity mSec = new EventWaitHandleSecurity();

        // Add a rule that grants the current user the
        // right to wait on or signal the event and read the
        // permissions on the event.
        EventWaitHandleAccessRule rule = new EventWaitHandleAccessRule(user,
                                                                       EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify
                                                                       | EventWaitHandleRights.ReadPermissions,
                                                                       AccessControlType.Allow);

        mSec.AddAccessRule(rule);

        // Add a rule that denies the current user the
        // right to change permissions on the event.
        rule = new EventWaitHandleAccessRule(user,
                                             EventWaitHandleRights.ChangePermissions,
                                             AccessControlType.Deny);
        mSec.AddAccessRule(rule);

        // Display the rules in the security object.
        ShowSecurity(mSec);

        // Create a rule that grants the current user
        // the full control over the event. Use the
        // SetAccessRule method to replace the
        // existing Allow rule with the new rule.
        rule = new EventWaitHandleAccessRule(user,
                                             EventWaitHandleRights.FullControl,
                                             AccessControlType.Allow);
        mSec.SetAccessRule(rule);

        ShowSecurity(mSec);
    }
예제 #3
0
        public bool Flush(int timeout)
        {
            // Special case for timeout = 0; just send the request and immediately return.
            if (timeout == 0)
            {
                FlushImpl();
                return(true);
            }

            // Create the wait handle with appropriate permissions.
            bool fCreatedNew;
            EventWaitHandleSecurity security = new EventWaitHandleSecurity();

            security.SetAccessRule(new EventWaitHandleAccessRule(new SecurityIdentifier(WellKnownSidType.ServiceSid, null), EventWaitHandleRights.Modify, AccessControlType.Allow));

            using (EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset, TRACE_FLUSH_EVENT_NAME, out fCreatedNew, security))
            {
                // Request the trace service to flush data, and wait for the service to signal completion.
                FlushImpl();
                return(waitHandle.WaitOne(timeout));
            }
        }