Example #1
0
        private void OnWatchedFileChanged(object source, FileSystemEventArgs e)
        {
            DateTime lastWriteTime = File.GetLastWriteTime(WatcherFullPath);

            if ((lastWriteTime - WatcherLastRead).Milliseconds > 100)
            {
                var fileInfo = new FileInfo(WatcherFullPath);
                while (File.Exists(WatcherFullPath) && IsFileLocked(fileInfo))
                {
                    //File is still locked, meaning the writing stream is still writing to the file,
                    // we need to wait until that process is done before trying to refresh it here.
                    System.Threading.Thread.Sleep(500);
                }

                ThreadHelper.JoinableTaskFactory.Run(async delegate {
                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                    if (Verbosity)
                    {
                        OutputLog.Log("External file change detected for " + Path.GetFileName(WatcherFullPath));
                    }
                    FileWatchedChanged?.Invoke();
                });

                WatcherLastRead = lastWriteTime;
            }
        }
Example #2
0
        private static void OnWatchedFileChanged(object source, FileSystemEventArgs e)
        {
            DateTime lastWriteTime = File.GetLastWriteTime(_fileWatcherFullPath);

            if (lastWriteTime != _fileWatcherLastRead)
            {
                Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.Run(async delegate {
                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                    FileWatchedChanged?.Invoke();
                });

                _fileWatcherLastRead = lastWriteTime;
            }
        }