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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:56:49+00:00 2026-06-06T11:56:49+00:00

I have a simple C# Console application in which I use FileSystemWatcher and Moving

  • 0

I have a simple C# Console application in which I use FileSystemWatcher and Moving files from one destiantion to another when they are created. My code looks like this:

    public static void WatchForFiles()
    {
        FileSystemWatcher watcher = new FileSystemWatcher();
        //folder path is path to folder
        watcher.Path = folderPath;

        watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
            | NotifyFilters.FileName | NotifyFilters.DirectoryName;

        //Add event handlers           
        watcher.Created += new FileSystemEventHandler(File_OnChanged);        

        //Begin watching
        watcher.EnableRaisingEvents = true;
    }


    public static void File_OnChanged(object sender, FileSystemEventArgs e)
    {
        //destiantion path is path to folder
        string destiantionFileFullPath = destianationPath + e.Name;
        if (!File.Exists(destiantionFileFullPath))
        {
            File.Move(e.FullPath, destiantionFileFullPath);
        }
    }

When I copy a file first time it is moved normally. But after that or if I copy two or more files my console windows is closed automatically. I think I should use IAsyncResult but I don’t know how. I tried Tasks but that didn’t help. Firs copying file and then deleting didn’t help either. What causes to this and how can I prevent this? Thanks in advance

  • 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-06-06T11:56:51+00:00Added an answer on June 6, 2026 at 11:56 am

    From experience, the use of FileWatcher to monitor files as they are dumped and (possibly) move them is more trouble than one would want to manage. Simple reason being that if files are dumped into the directory when your application is down, the FileWatcher wont catch them. I prefer using a Timer that polls at intervals, checking if there are files in the directory and moving them. Using this approach, if new files are dumped in the folder when the application is down (say for maintenance), they will be moved as soon as the app is restarted and the timer starts polling

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

Sidebar

Related Questions

I have a simple console application which runs daily (called by windows task scheduler)
I have a fairly intensive application, which I've just converted from a console application
I have the sample console application which is supposed to be executed in the
i have a simple .EXE console application, written in C# via Visual Studio 2008.
I have a simple test application (C# console application) that does an HTTP GET
I have simple SSIS package which reads data from flat file and insert into
I have a very simple Java application which downloads a set of foreign exchanges
My intend is to create a simple easily debuggable console application which will be
I have two databases in use in a Ruby on Rails application; one is
I have created a simple Todo application on JS Fiddle to learn Backbone.JS. I

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.