我编写了一个应用程序,它采用未压缩的 .wav 文件并编码为 flac 文件、mp3 文件和 aac 文件。flac 和 mp3 工作正常,但是在进行 aac 编码(使用Nero AAC 编码器)时,我随机收到有关正在使用的文件的 IOExceptions。有时 - 但不经常 - 它在文件生成时发生 - 我的进程创建的文件如何被另一个文件使用?但更常见的是,当我使用 TagLib 编写元标记时,我得到了错误。因此,我修改了代码以在出现 IO 错误时在相关文件上运行sysinternal 的 handle.exe,但它返回的事实是文件上没有句柄。这只是 Nero aac 编码器的固有问题吗?
try
{
if ( ! Directory.Exists( es.dest ) )
{
Directory.CreateDirectory( Path.GetDirectoryName( es.dest ) );
}
if ( File.Exists( es.dest ) ) { File.Delete( es.dest ); }
bool CommandGenerated = enc.GenerateCommandLine();
string procOutput = String.Empty;
if ( CommandGenerated )
{
Console.Out.WriteLine( "Starting:" );
p = new Process();
p.StartInfo.WorkingDirectory = Path.GetDirectoryName( current_config_exe );
p.StartInfo.FileName = current_config_exe;
p.StartInfo.Arguments = enc.ToString();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
procOutput = p.StandardOutput.ReadToEnd();
p.WaitForExit();
int exit_code = p.ExitCode;
p.Close();
p.Dispose();
string exit_msg = "Encoder exitcode: " + exit_code + "\n";
if ( exit_code != 0 )
{
Console.WriteLine( "There was a problem. Do you want to continue? (y/n) (Default = y)" );
string response = Console.ReadLine();
if ( response.ToLower() == "n" )
{
throw new Exception( "Note: " + exit_msg );
}
}
else if ( es.use_taglib_for_meta && enc.metaswitches != null )
{
Meta meta = new Meta( es.dest );
if ( meta.SetMetaTags( enc.metaswitches, true ) )
{
WriteLog( "Meta tags successfully wriiten to: \n" + es.dest, true, false );
}
else
{
WriteLog( "Meta tags NOT wriiten to: " + es.dest, true );
}
}
}
}
catch ( IOException ex )
{
Handler.GetHoldingProcess( es.dest );
Program.WriteLog( "(writing track to file) Error saving file " + es.dest + ":\n" + ex, true );
return false;
}