1
Reply

Call a function inside an event handler

Hesham Hassanein

Hesham Hassanein

Oct 6 2016 1:38 PM
326

Hello,

I am watching a directory so i am using system watcher and on the event handler, I would like when the event happens, to execute a function that does a specific job. How can i call a function inside the event handler or a way to say that when the event happens, go and do what is written in the following function. Thanks in Advance

  1. static void OnChanged(object source, FileSystemEventArgs e)  
  2.     {  
  3.         // Specify what is done when a file is changed, created, or deleted.  
  4.           
  5.         Console.WriteLine("File: " +  e.FullPath + " " + e.ChangeType);  
  6.         SomeGlobalVariables.counter++;  
  7.         SomeGlobalVariables.Range = SomeGlobalVariables.counter + 1;  
  8.         Console.WriteLine("Counter is" + SomeGlobalVariables.counter + "," + "Range is" + SomeGlobalVariables.Range);  
  9.   
  10. // Call function ReadData(string[,]Result)      
  11.   
  12.       
  13.     }  
  14.   
  15. static void ReadDATA(out string[,] Result)  
  16.         {  
  17. // Operation  
  18. // Or should i call the event handler here?  
  19. }  

Answers (1)