static void Main(string[] args) { var fileLister = new FileSearcher(); int filesFound = 0; // <SnippetDeclareEventHandler> EventHandler <FileFoundArgs> onFileFound = (sender, eventArgs) => { Console.WriteLine(eventArgs.FoundFile); filesFound++; }; fileLister.FileFound += onFileFound; // </SnippetDeclareEventHandler> // <SnippetSearch> fileLister.DirectoryChanged += (sender, eventArgs) => { Console.Write($"Entering '{eventArgs.CurrentSearchDirectory}'."); Console.WriteLine($" {eventArgs.CompletedDirs} of {eventArgs.TotalDirs} completed..."); }; // </SnippetSearch> fileLister.Search(".", "*.dll", true); // <SnippetRemoveHandler> fileLister.FileFound -= onFileFound; // </SnippetRemoveHandler> }
static void Main(string[] args) { var lister = new FileSearcher(); int filesFound = 0; EventHandler<FileFoundArgs> onFileFound = (sender, eventArgs) => { Console.WriteLine(eventArgs.FoundFile); filesFound++; //eventArgs.CancelRequested = true; }; lister.FileFound += onFileFound; lister.DirectoryChanged += (sender, eventArgs) => { Console.Write($"Entering '{eventArgs.CurrentSearchDirectory}'."); Console.WriteLine($" {eventArgs.CompletedDirs} of {eventArgs.TotalDirs} completed..."); }; lister.Search(".", "*.dll", true); lister.FileFound -= onFileFound; }
static void Main(string[] args) { var lister = new FileSearcher(); int filesFound = 0; EventHandler <FileFoundArgs> handler = (sender, eventArgs) => { Console.WriteLine(eventArgs.FoundFile); filesFound++; //eventArgs.CancelRequested = true; }; lister.OnFoundFile += handler; lister.OnChangeDirectory += (sender, eventArgs) => { Console.Write($"Entering '{eventArgs.CurrentSearchDirectory}'."); Console.WriteLine($" {eventArgs.CompletedDirs} of {eventArgs.TotalDirs} completed..."); }; lister.Search(".", "*.exe", true); lister.OnFoundFile -= handler; }