Trying to extract files over 1 GB using 7zip library. Code in c#. When trying to extract manually it works well, bit through c# code it takes longer or sometimes even hangs.
Below code I'm using
string arg = $"x -y -mx=1 -mmt=off <zipfile> -o<Outputpath>";
string sevenzip = @"<path_to_7zip>\7z.exe";
Process p = new Process()
{
StartInfo = new ProcessStartInfo()
{
FileName = sevenzip,
Arguments = arg,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true
}
};
p.Start();
string outputUnicode = null;
int exitCode=0;
CancellationToken token = default(CancellationToken);
GetProcessOutputWithTimeout(p, 7200000, token, out outputUnicode, out exitCode);
public void GetProcessOutputWithTimeout(Process process, int timeoutSec, CancellationToken token, out string output, out int exitCode)
{
string outputLocal = "";
int localExitCode = -1;
var task = System.Threading.Tasks.Task.Factory.StartNew(() =>
{
outputLocal = process.StandardOutput.ReadToEnd();
process.WaitForExit();
localExitCode = process.ExitCode;
}, token);
if (task.Wait(timeoutSec, token))
{
output = outputLocal;
exitCode = localExitCode;
}
else
{
exitCode = -1;
output = "";
}
if (process.HasExited == false)
{
process.Kill();
}
process.Close();
}
This code works well with smaller files but larger files takes more than 2 hours. I have kept timeout of 2 hours, because I don't want it to hang in between. Tried every possible way but no luck. Not sure what I'm doing wrong.