Пример #1
0
        static void Main(string[] args)
        {
            if (args.Count() > 0)
            {
                string directoryToWatch            = args[0];
                bool   includeSubDirectories       = false;
                int    eventResolutionMilliseconds = 10000;
                if (args.Count() > 1)
                {
                    includeSubDirectories = (args[1].ToLower() == "/s" ? true : false);
                }
                if (args.Count() > 2)
                {
                    try
                    {
                        eventResolutionMilliseconds = System.Convert.ToInt32(args[2]);
                    }
                    catch (Exception)
                    {
                    }
                    Console.WriteLine("Event Resolution is {0} milliseconds", eventResolutionMilliseconds);
                }

                try
                {
                    using (FileSystemObjectWatcher fileSystemObjectWatcher = new FileSystemObjectWatcher(
                               directoryToWatch,
                               includeSubDirectories,
                               ProcessFileSystemEvent,
                               eventResolutionMilliseconds))
                    {
                        // Wait for the user to quit the program

                        fileSystemObjectWatcher.BeginProcessing();

                        Console.WriteLine("Press \'q\' to quit File Watching");
                        int response = 0;
                        do
                        {
                            response = Console.Read();
                        } while (response != 'q');
                    }
                }
                catch (Exception eek)
                {
                    Console.WriteLine("Exception: \"{0}\"", eek.ToString());
                }
            }
        }