static void OnFileRenamedEvent(object sender, FileRenamedEventArgs e)
 {
     lock (Lock)
     {
         Console.WriteLine("OnFileRenamedEvent:");
         Console.WriteLine("  OldFilePath = {0}", e.OldFilePath);
         Console.WriteLine("  NewFilePath = {0}", e.NewFilePath);
         Console.WriteLine();
     }
 }
        /// <summary>
        /// Will raise the event on the current thread synchronously.
        /// i.e. it will wait until all event handlers have processed the event.
        /// </summary>
        /// <param name="e">The state to be passed to the event.</param>
        private void RaiseOnFileRenamedEvent(FileRenamedEventArgs e)
        {
            // Make a temporary copy of the event to avoid possibility of
            // a race condition if the last subscriber unsubscribes
            // immediately after the null check and before the event is raised.

            FileRenamedEventHandler eventHandler;

            if (!Monitor.TryEnter(_fileRenamedEventLock, _lockTimeout))
            {
                throw new ApplicationException("Timeout waiting for lock - RaiseOnFileRenamedEvent");
            }
            try
            {
                eventHandler = _fileRenamedEvent;
            }
            finally
            {
                Monitor.Exit(_fileRenamedEventLock);
            }

            OnFileRenamedEvent(e);

            if (eventHandler != null)
            {
                eventHandler(this, e);
            }
        }
 /// <summary>
 /// Will raise the event on the calling thread synchronously. 
 /// i.e. it will wait until all event handlers have processed the event.
 /// </summary>
 /// <param name="state">The state to be passed to the event.</param>
 private void RaiseCrossThreadOnFileRenamedEvent(FileRenamedEventArgs e)
 {
     _asyncOperation.SynchronizationContext.Send(new SendOrPostCallback(AsynchronousOnFileRenamedEventRaised), e);
 }
 /// <summary>
 /// Will raise the event on the calling thread asynchronously. 
 /// i.e. it will immediatly continue processing even though event 
 /// handlers have not processed the event yet.
 /// </summary>
 /// <param name="state">The state to be passed to the event.</param>
 private void RaiseAsynchronousOnFileRenamedEvent(FileRenamedEventArgs e)
 {
     _asyncOperation.Post(new SendOrPostCallback(AsynchronousOnFileRenamedEventRaised), e);
 }
 /// <summary>
 /// Template method to add default behaviour for the event
 /// </summary>
 private void OnFileRenamedEvent(FileRenamedEventArgs e)
 {
     // TODO: Implement default behaviour of OnFileRenamedEvent
 }
        private void OnFileRenamed(object sender, RenamedEventArgs e)
        {
            var filePath = e.FullPath;

            var isDirectory = Directory.Exists(filePath) && (File.GetAttributes(filePath) & FileAttributes.Directory) == FileAttributes.Directory;

            if (isDirectory)
            {
                lock (_filesRaisingEventsLock)
                {
                    var filesInDirectory = _filesChanging.Keys.Where(x => x.StartsWith(e.OldFullPath + "/"));

                    foreach (var fileInDirectory in filesInDirectory)
                    {
                        var fileInDirectoryPath = _filesChanging[fileInDirectory].FilePath;
                        Pop(fileInDirectory);

                        var fileFinishedChangingEventArgs = new FileFinishedChangingEventArgs(fileInDirectoryPath, FileEventType.Renamed, UserState);
                        RaiseAsynchronousOnFileFinishedChangingEvent(fileFinishedChangingEventArgs);
                    }
                }

                var directoryRenamedEventArgs = new DirectoryRenamedEventArgs(e.OldFullPath, e.FullPath, UserState);
                RaiseAsynchronousOnDirectoryRenamedEvent(directoryRenamedEventArgs);
                return;
            }

            if (!ShouldMonitorFile(filePath)) return;

            lock (_filesRaisingEventsLock)
            {
                if (_filesChanging.ContainsKey(filePath))
                {
                    Pop(filePath);

                    var fileFinishedChangingEventArgs = new FileFinishedChangingEventArgs(filePath, FileEventType.Renamed, UserState);
                    RaiseAsynchronousOnFileFinishedChangingEvent(fileFinishedChangingEventArgs);
                }
            }

            var fileRenamedEventArgs = new FileRenamedEventArgs(e.OldFullPath, e.FullPath, UserState);
            RaiseAsynchronousOnFileRenamedEvent(fileRenamedEventArgs);
        }