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 766199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T17:00:36+00:00 2026-05-14T17:00:36+00:00

I´m writing on an service to watch for the existence different files in diffent

  • 0

I´m writing on an service to watch for the existence different files in diffent folders…
I´m using filesystemwatchers to get the events.

As a part of the deployment one of the watched folders is deleted and new created from time to time.

As a result the service throws an error and is stopped…

Is it possible to catch that kind of error and recreate the filewatcher on the new folder by the service?

  • 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-14T17:00:37+00:00Added an answer on May 14, 2026 at 5:00 pm

    Catch the deleted event, and then reschedule with timed poll to watch a new one?

    I don’t have a compiler to hand right now but I knocked up this pseudo code:

    using System;
    using System.IO;
    
    
        public class Watcher : IDisposable{
    
        void Dispose(){ watcher.OnDeleted -= onDelete; }
    
    
        string file;
        FileSystemWatcher watcher; 
        FileSystemEventHandler onDelete;
    
            public class Watch(string file, FileSystemEventHandler onDelete) {
            this.file = file;   
            watcher = new FileSystemWatcher{ Path = file }
            this.OnDelete = onDelete;
            watcher.Deleted += onDelete;
            watcher.NotifyFilter = ...; // looking for delete event;
                // Begin watching.
                watcher.EnableRaisingEvents = true;
        }
        }
    
    
        public static class watch {
    
        Watcher watcher;
    
           public static void Main() {
    
    
    
            watcher = new Watcher("somedir", ondeleted);
            SetUpChangeWatchers();
            while(true){
                // stuff!
    
            }
    
            CleanUpChangeWatchers();    
           }    
    
    
        private static void ondeleted(object source, RenamedEventArgs e){ 
            CleanUpChangeWatchers();
            watcher.Dispose();
    
            while(!directoryRecreated(file)){
                Thread.Sleep(...some delay..);
            }
            SetUpChangeWatchers();  
            watcher = new Watcher("somedir", ondeleted);
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a RIA service, which is also exposed using SOAP. One of
I'm writing a service using Thrift and need to apply some tests to ensure
I am writing a web service using CXF and running under JBoss 6.0.0.Final. Right
I am new to android.. just started writing service using activity.. i want to
I am writing a service to a international HTTP standard, and there is one
I'm writing RESTful service with C#/wcf and need to put filters on GET. Like
I'm writing a service that has five different methods that can take between 5
I am writing a service using wcf. I have created a solution with two
I'm writing a Windows service to process files created by another process over which
I'm writing a service using plain C++ and the windows API and want it

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.