Пример #1
0
        /// <summary>
        /// Sets the debounce object and debounce time
        /// If debouncing is already in progres, updates the debounce object
        /// </summary>
        /// <param name="args">Object to be returned by the Debounced event</param>
        /// <param name="dueTime">The amount of debeounce time in milliseconds</param>
        /// <returns>true if debouncing is not already in progress</returns>
        public bool Start(string path, FileSystemEventArgs args, int dueTime)
        {
            bool started = false;
            var  key     = new DictionaryKey {
                Path = path, ChangeType = args.ChangeType
            };

            if (_dict.TryGetValue(key, out ObjectContainer oc))
            {
                oc.Args = args;
            }
            else
            {
                var container = new ObjectContainer(key, args);
                var t         = new Timer(DebouncerCallback, container, dueTime, Timeout.Infinite);
                container.Timer = t;
                _dict.TryAdd(key, container);
                started = true;
            }

            return(started);
        }
Пример #2
0
 public ObjectContainer(DictionaryKey key, FileSystemEventArgs args)
 {
     Key  = key;
     Args = args;
 }