我正在使用FilesystemWatcher类将音频转换为可听格式。这在一段时间内完美运行,直到我们在该服务器上升级到4.5时。现在,为了使它工作,我需要调试它并设置断点,以便在进程运行之前方法不会退出。
sox转换音频只需几毫秒。设置Thread.sleep(10000)不能解决问题。将项目降级为.net 2.0没有任何作用。
真正令人沮丧的是process.WaitForExit()似乎没有阻止。在调试时,我向右走,然后等到文件出现在文件夹中。
与往常一样,我非常感谢您的帮助。
附件是相关代码:
void FileCreated(object sender, FileSystemEventArgs e)
{
string newname = String.Format(@"{0}{1}.mp3", _mp3FolderPath, e.Name.Replace(".wav", ""));
string soxArgs = @"-t wav -r 8k -c 1";
ProcessStartInfo p = new ProcessStartInfo
{
FileName = _soxPath,
Arguments = string.Format("{0} {1} {2}", soxArgs, e.FullPath, newname),
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardError = false,
RedirectStandardInput = false,
RedirectStandardOutput = false
};
using (Process process = Process.Start(p))
{
process.WaitForExit();
Thread.Sleep(10000);
//process.Close();
}
}