Reputation: 21
the issue is as follows:
I'm using 7-zip to compress log files. as a stress test, i've made the max log file possible for 4k~ and i've made a task to bombard the logger with messages. since the compress function run a few times every second a weird behavior like a refresh happens. if i click/right click on some menu somewhere in windows it unfocus me and inside visual studio trying to search for something it selects my search text mid typing and i end up overwriting myself and more...
in reality this won't happen normally but still want to defend the application from this event if possible.
my compression function attempt currently is something like this:
private void CompressFile(string sourceName, string extension)
{
string targetName = sourceName.Replace(extension, ".zip");
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.FileName = @"C:\Program Files\7-Zip\7zG.exe";
processInfo.Arguments = "a -tgzip \"" + targetName + "\" \"" + sourceName + "\" -mx=9";
processInfo.CreateNoWindow = true;
processInfo.ErrorDialogParentHandle = IntPtr.Zero;
processInfo.WindowStyle = ProcessWindowStyle.Hidden;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardInput = true;
processInfo.RedirectStandardOutput = false;
Process presses = Process.Start(processInfo);
presses.WaitForExit();
}
i've tried changing some processInfo properties but had no much success so far.
Thanks in advance for any help/insight on the matter Roy.
Upvotes: 0
Views: 90
Reputation: 21
well after testing various options and reading online i reached the answer. since the executable 7zG.exe is the graphical exe of 7-zip even when i set processInfo.WindowStyle = ProcessWindowStyle.Hidden; the process opens the window and quickly hide it which caused the strange behavior. once i changed the FileName to the 7z.exe it stopped from happening.
the final version of the function:
private void CompressFile(string sourceName, string extension)
{
string targetName = sourceName.Replace(extension, ".zip");
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.FileName = @"C:\Program Files\7-Zip\7z.exe";
processInfo.Arguments = "a -tgzip \"" + targetName + "\" \"" + sourceName + "\" -mx=9";
processInfo.WindowStyle = ProcessWindowStyle.Hidden;
Process presses = Process.Start(processInfo);
presses.WaitForExit();
}
Upvotes: 1