I am using a FilesystemWatcher class to convert audio to a listenable format as they come in. This worked perfectly for a while, until right around the time we upgraded to 4.5 on that server. Now, to get it to work, I need to debug it and set a breakpoint so the method does not exit before the process runs.
It only takes a few milliseconds for sox to convert the audio. Setting a Thread.sleep(10000) doesnt fix the issue. Downgrading the project to .net 2.0 did nothing.
What's really frustrating, is process.WaitForExit() seemingly does not block. While debugging, I step right over it and wait until the file shows up in the folder.
As always, I really appreciate the assistance.
Attached is the relevant code:
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();
}
}