At the top of Form1, I did:
private Process zipFileDirectoryProcess;
In the constructor, I did:
zipFileDirectoryProcess = new Process(); zipFileDirectoryProcess.StartInfo.FileName = "explorer.exe"; zipFileDirectoryProcess.StartInfo.CreateNoWindow = true; zipFileDirectoryProcess.EnableRaisingEvents = true; zipFileDirectoryProcess.Exited += new EventHandler(zipFileDirectoryProcess_Exited);
Then I have a method that I call from the button click event:
private void Compress() { zipFileDirectoryProcess.StartInfo.Arguments = zipFileDirectoryProcess.StartInfo.Arguments = "/select," + Path.GetFullPath(t); zipFileDirectoryProcess.Start(); zipFileDirectoryProcess.WaitForExit(); this.TopMost = true; }
And then at the bottom of the Exited event:
private void zipFileDirectoryProcess_Exited(object sender, EventArgs e) { this.BeginInvoke(new MethodInvoker(delegate() { this.TopMost = false; })); }
What I wanted to do was only when I close the process window after it was started in this method only if the window / process was closed and then the Exited event occurs.
The problem is that after the process started in 2-3 seconds, it automatically goes to the Exited event.
How can i fix this? Tried examples can not understand. Tried to add this line:
zipFileDirectoryProcess.WaitForExit();
But no effect.
source share