internal DirMonCompletion(DirectoryMonitor dirMon, string dir, bool watchSubtree, uint notifyFilter)
        {
            this._dirMon = dirMon;
            NativeFileChangeNotification notification = new NativeFileChangeNotification(this.OnFileChange);

            this._rootCallback = GCHandle.Alloc(notification);
            int hr = UnsafeNativeMethods.DirMonOpen(dir, HttpRuntime.AppDomainAppIdInternal, watchSubtree, notifyFilter, notification, out this._ndirMonCompletionPtr);

            if (hr != 0)
            {
                this._rootCallback.Free();
                throw FileChangesMonitor.CreateFileMonitoringException(hr, dir);
            }
            this._ndirMonCompletionHandle = new HandleRef(this, this._ndirMonCompletionPtr);
            Interlocked.Increment(ref _activeDirMonCompletions);
        }
        private FileMonitor AddFileMonitor(string file)
        {
            FileMonitor  monitor;
            FindFileData data = null;
            int          num;

            if (string.IsNullOrEmpty(file))
            {
                monitor          = new FileMonitor(this, null, null, true, null, null);
                this._anyFileMon = monitor;
                return(monitor);
            }
            string fullPath = Path.Combine(this.Directory, file);

            if (this._isDirMonAppPathInternal)
            {
                num = FindFileData.FindFile(fullPath, this.Directory, out data);
            }
            else
            {
                num = FindFileData.FindFile(fullPath, out data);
            }
            if (num == 0)
            {
                if (!this._isDirMonAppPathInternal && ((data.FileAttributesData.FileAttributes & FileAttributes.Directory) != 0))
                {
                    throw FileChangesMonitor.CreateFileMonitoringException(-2147024809, fullPath);
                }
                byte[] dacl = FileSecurity.GetDacl(fullPath);
                monitor = new FileMonitor(this, data.FileNameLong, data.FileNameShort, true, data.FileAttributesData, dacl);
                this._fileMons.Add(data.FileNameLong, monitor);
                this.UpdateFileNameShort(monitor, null, data.FileNameShort);
                return(monitor);
            }
            if ((num != -2147024893) && (num != -2147024894))
            {
                throw FileChangesMonitor.CreateFileMonitoringException(num, fullPath);
            }
            if (file.IndexOf('~') != -1)
            {
                throw FileChangesMonitor.CreateFileMonitoringException(-2147024809, fullPath);
            }
            monitor = new FileMonitor(this, file, null, false, null, null);
            this._fileMons.Add(file, monitor);
            return(monitor);
        }