Question

I want to poll a directory for files every 5 minutes. I do NOT want to use filesystemwatcher. I am fairly new to c# and I cant find any good examples

This is what I have so far. Do I just put this in a timer?

    string watchFolder = ConfigurationManager.AppSettings["watchFolder"];
    DirectoryInfo directoryInfo = new DirectoryInfo(watchFolder);


    if (!Directory.Exists(watchFolder))
    {
        Console.WriteLine(
            "{0} directory does not exist. Please modify the config file accordingly.",
            watchFolder);
        Environment.Exit(3);
    }

    FileInfo[] lastUpdatedFiles = directoryInfo.GetFiles();
Was it helpful?

Solution

Putting it in a timer is probably your best solution, but which timer class to use may depend on this: Are you doing a console app, Winforms, or WPF? For Winforms use Timer.

For wpf use DispatcherTimer: WPF Timer Like C# Timer

In response to your clarifying comment, for services see this answer: Best Timer for using in a Windows service

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top