プロセス中に7za.exeウィンドウを閉じるのを防ぐ方法がありますか?フォルダ抽出の進捗状況を表示する必要がありますが、ユーザーがウィンドウを閉じると、C#プログラムでエラーが発生する可能性があります。プロセスが終了するまでユーザーが7za.exeプログラムを閉じることを避ける
public partial class ExtractForm : Form
{
public ExtractForm()
{
InitializeComponent();
}
private void ExtractForm_Load(object sender, EventArgs e)
{
InitializeEvent();
}
private void InitializeEvent()
{
Zip.LogFileExtract +=WriteExtractProgression;
}
private void WriteExtractProgression(string text)
{
if (InvokeRequired)
{
this.BeginInvoke(new Action<string>(WriteExtractProgression), text);
}
else
{
txtExtract.Text += text;
txtExtract.SelectionStart = txtExtract.TextLength;
txtExtract.ScrollToCaret();
txtExtract.Refresh();
}
}
}
Processメソッド:
ExtractForm extractForm = new ExtractForm();
extractForm.Show();
Process zipProcess = new Process();
using (zipProcess)
{
zipProcess.StartInfo.UseShellExecute = false; //Show the cmd.
zipProcess.StartInfo.RedirectStandardOutput = true;
zipProcess.OutputDataReceived += (object sender, DataReceivedEventArgs outline) =>
{
LogFileExtract(outline.Data);
// Add args to a TextBox, ListBox, or other UI element
};
zipProcess.StartInfo.CreateNoWindow = true;
zipProcess.StartInfo.FileName = pathToZip;
zipProcess.StartInfo.Arguments = args;
zipProcess.Start();
zipProcess.BeginOutputReadLine();
zipProcess.WaitForExit(); //Wait the process to finish completely.
}
extractForm.Close();
}
http://stackoverflow.com/questions/5377423/hide-console-window-from-process-start-c-sharpこれはあなたに答えますか? – Will
いいえ私はコンソールウィンドウが欲しいですが、私は自分でコンソールウィンドウを閉じることを望ましくありません。 –
あなたはおそらくSOLです。 – Will