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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:00:26+00:00 2026-05-16T17:00:26+00:00

I have to create a Windows service which monitors a specified folder for new

  • 0

I have to create a Windows service which monitors a specified folder for new files and processes it and moves it to other location.

I started with using FileSystemWatcher. My boss doesn’t like FileSystemWatcher and wants me to use polling by using a Timer or any other mechanism other than FileSystemWatcher.

How can you monitor directorying without using FileSystemWatcher using .NET framework?

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

    Using @Petoj’s answer I’ve included a full windows service that polls every five minutes for new files. Its contrained so only one thread polls, accounts for processing time and supports pause and timely stopping. It also supports easy attaching of a debbugger on system.start

     public partial class Service : ServiceBase{
    
    
        List<string> fileList = new List<string>();
    
        System.Timers.Timer timer;
    
    
        public Service()
        {
            timer = new System.Timers.Timer();
            //When autoreset is True there are reentrancy problems.
            timer.AutoReset = false;
    
            timer.Elapsed += new System.Timers.ElapsedEventHandler(DoStuff);
        }
    
    
        private void DoStuff(object sender, System.Timers.ElapsedEventArgs e)
        {
           LastChecked = DateTime.Now;
    
           string[] files = System.IO.Directory.GetFiles("c:\\", "*", System.IO.SearchOption.AllDirectories);
    
           foreach (string file in files)
           {
               if (!fileList.Contains(file))
               {
                   fileList.Add(file);
    
                   do_some_processing();
               }
           }
    
    
           TimeSpan ts = DateTime.Now.Subtract(LastChecked);
           TimeSpan MaxWaitTime = TimeSpan.FromMinutes(5);
    
           if (MaxWaitTime.Subtract(ts).CompareTo(TimeSpan.Zero) > -1)
               timer.Interval = MaxWaitTime.Subtract(ts).TotalMilliseconds;
           else
               timer.Interval = 1;
    
           timer.Start();
        }
    
        protected override void OnPause()
        {
            base.OnPause();
            this.timer.Stop();
        }
    
        protected override void OnContinue()
        {
            base.OnContinue();
            this.timer.Interval = 1;
            this.timer.Start();
        }
    
        protected override void OnStop()
        {
            base.OnStop();
            this.timer.Stop();
        }
    
        protected override void OnStart(string[] args)
        {
           foreach (string arg in args)
           {
               if (arg == "DEBUG_SERVICE")
                       DebugMode();
    
           }
    
            #if DEBUG
                DebugMode();
            #endif
    
            timer.Interval = 1;
            timer.Start();
       }
    
       private static void DebugMode()
       {
           Debugger.Break();
       }
    
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an windows service that monitors a folder for new files being created.when
I have two windows application, one is a windows service which create EventWaitHandle and
I have written a service that monitors a file drop location for files from
i have a WCF service which Monitors a Particular Drive and Creates a New
I have created a C# .Net windows service. There are some configuration files which
I have a Windows service (C#) where I create multiple threads which will try
I have written a windows service, which monitors a database table for pending jobs
I have a project ongoing at the moment which is create a Windows Service
I have create a windows service app with resources (.resx) files on it. Now
I have two processes in my app. 1. myService.exe which is a windows service.

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.