Example #1
0
        private void PostEvent(string filename, FileSystemWatcher fsw, FileAction fa, FileSystemInfo changedFsi)
        {
            RenamedEventArgs renamedEventArgs = null;

            if (fa == (FileAction)0)
            {
                return;
            }
            if (fsw.IncludeSubdirectories && fa == FileAction.Added && changedFsi is DirectoryInfo)
            {
                KeventData keventData = new KeventData();
                keventData.FSW            = fsw;
                keventData.Directory      = changedFsi.FullName;
                keventData.FileMask       = fsw.MangledFilter;
                keventData.IncludeSubdirs = fsw.IncludeSubdirectories;
                keventData.Enabled        = true;
                lock (this)
                {
                    KeventWatcher.StartMonitoringDirectory(keventData);
                }
            }
            if (!fsw.Pattern.IsMatch(filename, true))
            {
                return;
            }
            lock (fsw)
            {
                fsw.DispatchEvents(fa, filename, ref renamedEventArgs);
                if (fsw.Waiting)
                {
                    fsw.Waiting = false;
                    System.Threading.Monitor.PulseAll(fsw);
                }
            }
        }
Example #2
0
        public void StartDispatching(FileSystemWatcher fsw)
        {
            KeventData keventData;

            lock (this)
            {
                if (KeventWatcher.thread == null)
                {
                    KeventWatcher.thread = new Thread(new ThreadStart(this.Monitor));
                    KeventWatcher.thread.IsBackground = true;
                    KeventWatcher.thread.Start();
                }
                keventData = (KeventData)KeventWatcher.watches[fsw];
            }
            if (keventData == null)
            {
                keventData                = new KeventData();
                keventData.FSW            = fsw;
                keventData.Directory      = fsw.FullPath;
                keventData.FileMask       = fsw.MangledFilter;
                keventData.IncludeSubdirs = fsw.IncludeSubdirectories;
                keventData.Enabled        = true;
                lock (this)
                {
                    KeventWatcher.StartMonitoringDirectory(keventData);
                    KeventWatcher.watches[fsw] = keventData;
                    KeventWatcher.stop         = false;
                }
            }
        }
Example #3
0
 private void Monitor()
 {
     while (!KeventWatcher.stop)
     {
         kevent ev = default(kevent);
         ev.udata = IntPtr.Zero;
         kevent kevent = default(kevent);
         kevent.udata = IntPtr.Zero;
         timespec timespec = default(timespec);
         timespec.tv_sec  = 0;
         timespec.tv_usec = 0;
         int num;
         lock (this)
         {
             num = KeventWatcher.kevent(KeventWatcher.conn, ref kevent, 0, ref ev, 1, ref timespec);
         }
         if (num > 0)
         {
             KeventData data = (KeventData)KeventWatcher.requests[ev.ident];
             KeventWatcher.StopMonitoringDirectory(data);
             KeventWatcher.StartMonitoringDirectory(data);
             this.ProcessEvent(ev);
         }
         else
         {
             Thread.Sleep(500);
         }
     }
     lock (this)
     {
         KeventWatcher.thread = null;
         KeventWatcher.stop   = false;
     }
 }