我在我的 Form1 按钮单击事件中有这一行:
Process.Start(Path.GetFullPath(zippedFileDirectory));
它只是打开这个目录的位置。然后我有另一行:
Process.Start(Path.GetFullPath(temp));
如果我单击第一个按钮,然后单击第二个按钮,我将在每个进程中打开两个窗口。
现在我正在关闭我的程序,所以在 Form1 关闭事件中我想杀死这两个进程。
在其他部分我该怎么办?
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("Are you Sure you want to Exit. Click Yes to Confirm and No to continue", "WinForm",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
e.Cancel = true;
}
else
{
}
}
编辑:
我现在在我的 Form1 顶部添加了:
private Process zipFileDirectoryProcess;
然后在我所做的方法的底部:
private void Compress()
{
string zipFileName = "Diagnosis_Files.zip";
string source = contentDirectory;
string output = zippedFileDirectory;
string programFilesX86 = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86)
+ "\\Diagnostic Tool\\7z.dll";
if (File.Exists(programFilesX86))
{
SevenZipExtractor.SetLibraryPath(programFilesX86);
}
string programFiles = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles)
+ "\\Diagnostic Tool\\7z.dll";
if (File.Exists(programFiles))
{
SevenZipExtractor.SetLibraryPath(programFiles);
}
SevenZipCompressor compressor = new SevenZipCompressor();
compressor.ArchiveFormat = OutArchiveFormat.Zip;
compressor.CompressionMode = CompressionMode.Create;
compressor.TempFolderPath = System.IO.Path.GetTempPath();
string t = Path.Combine(output, zipFileName);
compressor.CompressDirectory(source, t);
zipFileDirectoryProcess.Start(Path.GetFullPath(zippedFileDirectory));
this.TopMost = true;
}
我添加了这一行:
zipFileDirectoryProcess.Start(Path.GetFullPath(zippedFileDirectory));
但我在这一行得到一个错误:
Error 1 Member 'System.Diagnostics.Process.Start(string)' cannot be accessed with an instance reference; qualify it with a type name instead
在我添加这一行之前,我有这一行:
Process.Start(Path.GetFullPath(zippedFileDirectory));
而且效果很好,为什么现在我有这个错误?