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

  • SEARCH
  • Home
  • 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 7171765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:28:44+00:00 2026-05-28T15:28:44+00:00

I have about 5-6 Server Manager programs that write their own configuration file out

  • 0

I have about 5-6 Server Manager programs that write their own configuration file out to a particualr folder, such as C:\ACME. The config files all end with a *ServerConfig.cfg” where * = Program name that created it.

I have a Windows service that has a FileSystemWatcher setup that I want to FTP the configuration files each time the program updates. I’ve gotten everything to work, but I’m noticing that the different Server Manager programs are behaving differently.

When saving a configuration file, the FileSystemWatcher is picking up two “change” events. This is causing my program to FTP the configuration file twice where I only need it once.

In other instances I’m seeing where it may create 4, 5, or 6 “change” events when saving a configuration file.

What is the best way to handle processing/FTPing these files when they are really done saving only one time.

I really dont want o set something up to poll the directory for filechanges every so often… and like the idea that each time a configuration is saved, I get a duplicate copy along with a date/timestamp appended to the filename copied elsewhere.

I have seen lots of suggestions Googling around and even here on Stackoverflow, but nothing that seems to be all-in-one for me.

I suppose I could put the filename in a queue when a “change” event occurred if it didn’t already exist in the queue. Not sure if this is the best approx.

Here is my sample code:

Startup-code:

private DateTime _lastTimeFileWatcherEventRaised = DateTime.Now;

_watcherCFGFiles = new FileSystemWatcher();
_watcherCFGFiles.Path = @"C:\ACME";
_watcherCFGFiles.IncludeSubdirectories = true;
_watcherCFGFiles.Filter = "*ServerConfig.cfg";

_watcherCFGFiles.NotifyFilter = NotifyFilters.Size;
//_watcherCFGFiles.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.FileName;

_watcherCFGFiles.Changed += new FileSystemEventHandler(LogFileSystemChanges);
_watcherCFGFiles.Created += new FileSystemEventHandler(LogFileSystemChanges);
_watcherCFGFiles.Deleted += new FileSystemEventHandler(LogFileSystemChanges);
_watcherCFGFiles.Renamed += new RenamedEventHandler(LogFileSystemRenaming);
_watcherCFGFiles.Error += new ErrorEventHandler(LogBufferError);
_watcherCFGFiles.EnableRaisingEvents = true;  

Here is that actual handler for the “change” event. I’m skipping the first “change” event if the second is within 700ms. But this doesn’t account for the files that make 3-4 change events…

    void LogFileSystemChanges(object sender, FileSystemEventArgs e)
    {
        string log = string.Format("{0} | {1}", e.FullPath, e.ChangeType);

        if( e.ChangeType == WatcherChangeTypes.Changed ) 
        { 
            if(DateTime.Now.Subtract(_lastTimeFileWatcherEventRaised).TotalMilliseconds < 700) 
            { 
                return; 
            }  

           _lastTimeFileWatcherEventRaised = DateTime.Now;

           LogEvent(log);

           // Process file
           FTPConfigFileUpdate(e.FullPath);   
       }
     }
  • 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-28T15:28:45+00:00Added an answer on May 28, 2026 at 3:28 pm

    I had the exact same issue. I used a HashMap that mapped filenames to times of writes, I then used this as a lookup table for files to check and see if the changed event had been applied very quickly. I defined some epsilon (for me it was about 2 seconds to make sure events were flushed). If the time found in the map was older than that I would put it on a queue to be processed. Essentially all I had to do was keep the HashMap up to date with events and changes and this worked out (although you may want to change your epsilon value depending on your application).

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

Sidebar

Related Questions

I have a Server 2003 box with about 6 sites that each have about
I have a table on SQL Server 2005 that was about 4gb in size.
I have a question about SQL Server indexes. I'm not a DBA and assume
I have a question about wiring web server controls. From many of the examples
I am after so advice really. I have been thinking about a client server
I have found many tutorials about using Windows Server 2003 as a development machine,
i have a general question about how sql server evaluates the joins.The query is
I have a Linux web server farm with about 5 web servers, web traffic
I'm brand new to SQL Server 2008, and have some newbie questions about the
We have about 7 app servers running .NET windows services that ping a single

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.