So, I am using Execute Shell in a program I am working with and I need to zip some files by command, I decided to use 7zip as it comes with NuGet. I also added a message for the final user saying that the process got completed, I got that message 30 seconds before the process actually completes, so after the message 30 seconds must passed for me to be able to open/access the zip file.
is there any way to keep a track of it or display the message until the process is completed? tried with threads, if statements, whiles, do while, and some more but still no luck, this is how some of the code looks for the zipping part
public static void ZipFiles()
{
ExecuteShell ES = new ExecuteShell();
ES.ExecuteCommand("cmd.exe", zipCmdText, false, false,
"C:\\Windows\\System32", "");
}
and the execute shell part:
public bool ExecuteCommand(string EXEName, string Command, bool
blnCallWaitForExit, bool blnBatchFile, string strWorkingDirectory, string
ExecutionDoneMessage)
{
bool blnCommandExited = false;
try
{
KillAllCommandExe(EXEName);
List<string> OutPut = new List<string>();
objProcess = new Process();
objProcess.OutputDataReceived += new DataReceivedEventHandler(objProcess_OutputDataReceived);
objProcess.ErrorDataReceived += new DataReceivedEventHandler(objProcess_ErrorDataReceived);
objProcess.Exited += new EventHandler(objProcess_Exited);
objProcess.StartInfo.FileName = EXEName;
if(!blnBatchFile)
objProcess.StartInfo.Arguments = Command;
objProcess.StartInfo.UseShellExecute = false;
if (strWorkingDirectory != "")
objProcess.StartInfo.WorkingDirectory = strWorkingDirectory;
objProcess.StartInfo.RedirectStandardInput = true;
objProcess.StartInfo.RedirectStandardOutput = true;
objProcess.StartInfo.RedirectStandardError = true;
objProcess.StartInfo.CreateNoWindow = true;
objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
objProcess.Start();
objProcess.BeginOutputReadLine();
objProcess.BeginErrorReadLine();
if (blnCallWaitForExit == true)
{
objProcess.WaitForExit(9000);
}
if (objProcess.HasExited)
{
CloseProcess();
}
blnCommandExited = true;
}
catch (Exception ex)
{
}
return blnCommandExited;
}
Are there any other better/faster zipping options that could achieve this result?
Any suggestion will be greatly appreciated.