1

我编写了一个应用程序,它采用未压缩的 .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;
    }
4

1 回答 1

1

我建议您使用其他 SysInternals 工具 - filemon.exe

  1. 在抱怨 IOException 的方法上放置断点
  2. 从 VS 以调试模式运行应用程序
  3. 当 VS 在断点处停止时 - 启动 filemon.exe
  4. VS中按F5(继续执行)
  5. 引发异常时 - 暂停 filemon.exe 并开始分析文件的情况

为了简化调查,您可以通过文件或进程名称在 filemon 中设置过滤器祝您好运!

于 2011-08-13T19:06:25.490 回答