gpt4 book ai didi

c# - FileSystemWatcher 不会为在 ffmpeg 中打开的文件触发事件

转载 作者:行者123 更新时间:2023-12-04 23:14:54 25 4
gpt4 key购买 nike

我正在尝试检查文件上次使用 FileSystemWatcher 更改其大小的时间,但该文件仍在另一个程序(ffmpeg.exe)中打开。我不知道为什么不触发更改的事件。
以下是我的代码:

using (var proc = new Process())
{

Console.WriteLine("Iniciando gravação da stream:"+url);
proc.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + @"\ffmpeg.exe";
proc.StartInfo.Arguments = @"-y -i " + url + @" -ab 32k -ac 1 -ar 11025 " + idStation + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".mp3";

proc.StartInfo.RedirectStandardOutput = true;

proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardInput = true;

proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;

proc.EnableRaisingEvents = true;

proc.Start();

proc.BeginOutputReadLine();
proc.BeginErrorReadLine();


proc.ErrorDataReceived += new DataReceivedEventHandler(CheckOutput);

FileSystemWatcher fileSizeChecker = new FileSystemWatcher();
fileSizeChecker.Changed += WatchFile;
fileSizeChecker.Path = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory + @"\" + idStation + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".mp3");
fileSizeChecker.Filter = Path.GetFileName(AppDomain.CurrentDomain.BaseDirectory + @"\" + idStation + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".mp3");
fileSizeChecker.EnableRaisingEvents = true;
fileSizeChecker.BeginInit();
}
static void WatchFile(object sender, FileSystemEventArgs e)
{
Console.WriteLine(DateTime.Now.ToString("T") + "] Watcher changed!");
}

WatchFile 永远不会被调用。

最佳答案

关于c# - FileSystemWatcher 不会为在 ffmpeg 中打开的文件触发事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48584182/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com