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
- static void OnCreated(object source, FileSystemEventArgs e)
- {
- int P_Count = 0;
- // Specify what is done when a file is created
- Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
- SomeGlobalVariables.fileName = e.FullPath;
- SomeGlobalVariables.counter++;
- string[] fileArray = new string[SomeGlobalVariables.counter];
- for (int count = 0; count <= fileArray.Length - 1; count++)
- {
- fileArray[count] = SomeGlobalVariables.fileName;
- SomeGlobalVariables.filenameslist.Add(fileArray[count]);
- P_Count = P_Count + 1; // Number of added files
- Console.WriteLine ("Number of Files in the list = " + P_Count);
- foreach (var filenames in SomeGlobalVariables.filenameslist)
- {
- var fileName = filenames;
- var Name_File = Path.GetFileName(fileName);
- var tempfilepath = (@"C:\Users\" + Name_File + ".CSV");
- }
- }
- static void ReadData()
- {
- using (System.IO.StreamWriter tempfile = new System.IO.StreamWriter(tempfilepath))
- {
- System.IO.StreamReader reader = new System.IO.StreamReader(fileName);
- }}
theLizardPosted Oct 11, 2016, 4:34 PM
That's it, this will be done for each new file created.
Madhanmohan DevarajanPosted Oct 7, 2016, 12:12 PM
{
int P_Count = 0;
// Specify what is done when a file is created
Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
//SomeGlobalVariables.fileName = e.FullPath;
//SomeGlobalVariables.counter++;
Madhanmohan DevarajanPosted Oct 7, 2016, 11:11 AM