Hesham Hassanein

Hesham Hassanein

  • NA
  • 140
  • 16.1k

Passing paramters from event handler to another function

Oct 7 2016 10:50 AM
How can i pass a var parameter from event handler to another function
 I am watching a directory and doing an event handler when file is created go to the function ReadData. So how can i pass the values of tempfilepath and fileName to ReadData function?. thanks in advance
  1. static void OnCreated(object source, FileSystemEventArgs e)  
  2.        {  
  3.            int P_Count = 0;  
  4.            // Specify what is done when a file is created  
  5.            Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);  
  6.   
  7.              
  8.            SomeGlobalVariables.fileName = e.FullPath;  
  9.            SomeGlobalVariables.counter++;  
  10.   
  11.              
  12.            string[] fileArray = new string[SomeGlobalVariables.counter];  
  13.            for (int count = 0; count <= fileArray.Length - 1; count++)  
  14.            {  
  15.   
  16.                fileArray[count] = SomeGlobalVariables.fileName;  
  17.                SomeGlobalVariables.filenameslist.Add(fileArray[count]);  
  18.                P_Count = P_Count + 1;                                               // Number of added files  
  19.                  
  20.                  
  21.                Console.WriteLine ("Number of Files in the list = " + P_Count);      
  22.                  
  23.                foreach (var filenames in SomeGlobalVariables.filenameslist)  
  24.                    {  
  25.                        var fileName = filenames;  
  26.                        var Name_File = Path.GetFileName(fileName);  
  27.                        var tempfilepath = (@"C:\Users\" + Name_File + ".CSV");  
  28.                          
  29.                         
  30.                    }  
  31.   
  32.              
  33.              
  34.            }         
  35.   
  36. static void ReadData()   
  37.    {  
  38.       
  39.   
  40.   
  41.        using (System.IO.StreamWriter tempfile = new System.IO.StreamWriter(tempfilepath))  
  42.        {  
  43.              
  44.            System.IO.StreamReader reader = new System.IO.StreamReader(fileName);       
  45.            }}  
 

Answers (3)