File change event Hit more than once. RRS feed

  • Question

  • Hi,

    I am registering the file we add in project for tracking changes to file. For this I have used IVsFileChangeEvents. Problem is when i add the file to the project then also it is hitting IVsFileChangeEvents.FilesChanged method and it is hitting the the method more than once. 

    I do not want this method to be hit when we add a file in the project. I want this method to be hit only when we change the content of the file. And also it should not hit more than once.

    Code is attached.

    //below code is registering the file to file change event
     string scFileName = System.IO.Path.GetDirectoryName(_ProjectNode.Url) + "\\" + _currentFileName + FileExtension;
                                    //subscribe to file watcher.
                                    SourceControlOpenUpdate _openUpdate = new SourceControlOpenUpdate(_ProjectNode, HostConnector, _ProjectNode.Url);
                                    FileChangeTracker fileChangeTracker = new FileChangeTracker(_ProjectNode.Site, scFileName);
                                    fileChangeTracker.UpdatedOnDisk += _openUpdate.SourceControlFileChanged;
                                    fileAddVariable = true;
    //below method is hitting again and again
    int IVsFileChangeEvents.FilesChanged(uint changeCount, string[] files, uint[] changes)
                var handler = UpdatedOnDisk;
                if (handler != null)
                    handler(this, EventArgs.Empty);
                _fileChangeService.AdviseFileChange(_filePath, (uint)_VSFILECHANGEFLAGS.VSFILECHG_Time, this, out newCookie);
                return 0;

    Please anyone can help.

    Thanks in advance

    • Moved by CoolDadTx Tuesday, January 24, 2017 2:51 PM Extensibility related
    Tuesday, January 24, 2017 6:43 AM

All replies

  • Hi abhi0022,

    Based on your description, I am not sure what kind of project template you are using, where you invoke the IVsFileChangeEvents.FilesChanged.

    In addition, please set a breadpoint at related invoking location and check what cause invoking the method many times.  

    Best regards,

    Cole Wu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, January 25, 2017 1:48 AM