无法访问文件,因为它在另一个进程中使用

时间:2014-12-11 15:44:08

标签: c#

编译器正在给我这个:

  

该进程无法访问该文件,因为该文件正由另一个进程使用。

我认为File.WriteAllBytes是问题。

代码:

    File.Move(currentDir, @"uncompressed/" + filename);
    string fileName2 = Path.Combine(Path.GetTempPath(), "tempfile.exe");
    File.WriteAllBytes(fileName2, SC_Editor.Properties.Resources.ucsgflzma);
    string arguments = "uncompressed decompressed *.* -d";
    ProcessStartInfo psi = new ProcessStartInfo(fileName2, arguments)
    {
        CreateNoWindow = true,
        WindowStyle = ProcessWindowStyle.Hidden,
        UseShellExecute = false,
        RedirectStandardOutput = true
    };
    Process process = Process.Start(psi);
    getPngs();
}
else
{
    label2.Visible = false;
    label3.Visible = false;
    MessageBox.Show("Uhm, that's not an .sc file..", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void getPngs()
{
    label7.Text = "Getting .png's...";
    string fileName3 = Path.Combine(Path.GetTempPath(), "tempfile.exe");
    string arguments2 = @"decompressed pngs *.*";
    File.WriteAllBytes(fileName3, SC_Editor.Properties.Resources.ucssc);
    ProcessStartInfo psi2 = new ProcessStartInfo(fileName3, arguments2)
    {
        CreateNoWindow = true,
        WindowStyle = ProcessWindowStyle.Hidden,
        UseShellExecute = false,
        RedirectStandardOutput = true
    };
    Process process = Process.Start(psi2);
}

0 个答案:

没有答案