Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3282406
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:55:28+00:00 2026-05-17T19:55:28+00:00

Ok, so I learnt from How to check if a open file has been

  • 0

Ok, so I learnt from How to check if a open file has been updated that I should use a FileSystemWatcher to watch for changes to files. Then now, the question is if I must keep track of many files, do I create 1 watcher for each file? Also, I must somehow dispose of the watcher once the file is closed. Is having a Dictionary<string, FileSystemWatcher> storing the filepath and the FileSystemWatcher the way to go? as I open more files, I add more watcher and as I close, dispose of the watchers appropriately. Will having too many watchers be a bad thing?

UPDATE

I just did

protected void AttachFileMonitor(EditorTabViewModel tab)
{
    string file = tab.FilePath;
    if (!_fsWatchers.ContainsKey(file))
    {
        var watcher = new FileSystemWatcher();
        watcher.Path = Path.GetDirectoryName(file);
        watcher.Filter = Path.GetFileName(file);
        watcher.Changed += (s, e) =>
        {
            string message = "";
            string caption = "";
            MessageBoxButton buttons = MessageBoxButton.YesNo;
            MessageBoxImage image = MessageBoxImage.Question;
            MessageBoxResult defaultResult = MessageBoxResult.Yes;
            MessageBoxResult result = _dialogSvc.GetMessageBox(message, caption, buttons, image, defaultResult);
            if (result == MessageBoxResult.Yes)
            {
                tab.Open(file);
            }
        };
        _fsWatchers.Add(file, watcher);
    }
}
protected void DetachFileMonitor(EditorTabViewModel tab)
{
    if (_fsWatchers.ContainsKey(tab.FilePath)) {
        _fsWatchers.Remove(tab.FilePath);
    }
}

I found that Changed() never gets triggered …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:55:29+00:00Added an answer on May 17, 2026 at 7:55 pm

    It’s enough if you create a watcher for each directory (and optionally, you can have the watcher to monitor a whole directory tree.) You can then use the events to compare the changed files with the list of files you are interested in.

    I would suggest you make some kind of “nanny” class for the watchers to ensure you doesn’t dispose active watchers, or create duplicate. Just a tip 🙂

    Btw, yes, there’s a limit, you can’t create infinite watchers. In specific scenarios that can be a problem, but most likely, that’s not the case for you

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From previous post, I learnt that for there are two ways, at least, to
I recently learnt that oracle has a feature which was pretty useful to me
For some time I am worknig in MVC, I learnt from this post, http://evolpin.wordpress.com/2011/04/12/asp-net-mvc-partialview-with-ajax/#comment-435
Lately, I've been trying to learn C++ from this website . Unfortunately whenever I
I want to learn WPF but from all the commentary I've been hearing the
I have 10 arbitrary letters and need to check the max length match from
I am trying to download a file from a site using perl. I chose
One day I pressed in Eclipse Help -> Check for Updates (and I learnt
I use php GET to check for an ID in an URL, then retrieve
hi to all i have a table that is named books and it has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.