// Define the event handlers. internal static void OnChanged(object source, FileSystemEventArgs e) => // actions when adding a new file // file processing Task.Run(() => { using (StreamReader streamReader = new StreamReader(e.FullPath, Encoding.Default)) { byte[] bytes = streamReader.CurrentEncoding.GetBytes(streamReader.ReadToEnd()); FileInfo fileInfo = new FileInfo(e.FullPath); // Check the format of the file name 1 if (ValidateFileName(fileInfo.Name)) { WorkWithFile(bytes); MessageUtility.ShowInformationMessage("OK"); } else { MessageUtility.ShowValidationMessage("Invalid file format!"); } } });