fix the event void, I expect it to run once not trigger many times this is a common…
- User
fix the event void, I expect it to run once not trigger many times this is a common problem with events please correct
private void OnChangedWhisperREC(object sender, FileSystemEventArgs e) { string outputTXT = string.Empty; if (hacktwo == 1) { if (e.ChangeType != WatcherChangeTypes.Changed && e.ChangeType != WatcherChangeTypes.Created && e.ChangeType != WatcherChangeTypes.Deleted && e.ChangeType != WatcherChangeTypes.Renamed) { return; // Ignore unsupported file events }
codestring filePath = e.FullPath; string directory = Path.GetDirectoryName(filePath); string fileName = Path.GetFileName(filePath); string newFilePath = Path.Combine(directory, Path.ChangeExtension(fileName, "temp")); while (true) { try { File.Copy(filePath, newFilePath, true); // Overwrite if already exists filePath = newFilePath; newFilePath = Path.Combine(directory, Path.ChangeExtension(fileName, Path.GetRandomFileName())); break; // Copied successfully, proceed to reading the file } catch (IOException) { // The file is still in use. Wait for a short interval and try again. System.Threading.Thread.Sleep(100); } } try { using (var fileStream = File.OpenRead(filePath)) using (var reader = new StreamReader(fileStream)) { try { outputTXT = reader.ReadToEnd(); outputTXT = RemoveUnwantedParts(outputTXT); fileStream.Close(); reader.Close(); } catch { MessageBox.Show("Error: Try Again!"); } } } finally { // Delete the temporary file if it exists if (File.Exists(newFilePath)) { File.Delete(newFilePath); } TTSAPI(outputTXT); } } - Assistant
- User
fix the event void, I expect it to run once not trigger many times this is a common problem with events please correct
private void OnChangedWhisperREC(object sender, FileSystemEventArgs e) { string outputTXT = string.Empty; if (hacktwo == 1) { if (e.ChangeType != WatcherChangeTypes.Changed && e.ChangeType != WatcherChangeTypes.Created && e.ChangeType != WatcherChangeTypes.Deleted && e.ChangeType != WatcherChangeTypes.Renamed) { return; // Ignore unsupported file events }
code - Assistant