示例#1
0
        public void DoMonitoring()
        {
            try
            {
                // Open the file
                asyncFileReader = new AsynchronousFileReader(fileDir + fileName);

                // Create a new FileSystemWatcher and set its properties.
                watcher = new FileSystemWatcher();

                watcher.Path                = fileDir;                               // set the path
                watcher.Filter              = fileName;                              // set the file
                watcher.NotifyFilter        = NotifyFilters.Size;                    // look for size change
                watcher.Changed            += new FileSystemEventHandler(OnChanged); // Add event handler(s)
                watcher.EnableRaisingEvents = true;                                  // Begin watching

                //ReadAndPrintFromFile(1000);                               // Perform an initial read

                // No initial read, only watch new changes
                asyncFileReader.fileStream.Position = asyncFileReader.fileStream.Length;
            }

            catch (Exception _e)
            {
                Console.WriteLine("!!!!!!!!!!!!!!!!!!");
                Console.WriteLine(_e.ToString());
                Console.WriteLine("!!!!!!!!!!!!!!!!!!");
            }
        }
示例#2
0
        public void DoMonitoring()
        {
            try
            {
                // Open the file
                asyncFileReader = new AsynchronousFileReader(fileDir + fileName);

                // Create a new FileSystemWatcher and set its properties.
                watcher = new FileSystemWatcher();

                watcher.Path = fileDir;                                   // set the path
                watcher.Filter = fileName;                                // set the file
                watcher.NotifyFilter = NotifyFilters.Size;                // look for size change
                watcher.Changed += new FileSystemEventHandler(OnChanged); // Add event handler(s)
                watcher.EnableRaisingEvents = true;                       // Begin watching

                //ReadAndPrintFromFile(1000);                               // Perform an initial read

                // No initial read, only watch new changes
                asyncFileReader.fileStream.Position = asyncFileReader.fileStream.Length;
            }

            catch (Exception _e)
            {
                Console.WriteLine("!!!!!!!!!!!!!!!!!!");
                Console.WriteLine(_e.ToString());
                Console.WriteLine("!!!!!!!!!!!!!!!!!!");
            }
        }