프로세스 호출 대기 및 프로세스 종료 모니터링 소스
2558 단어 원본 코드
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
}
/// <summary>
///
/// </summary>
/// <param name="appPath"> </param>
/// <param name="args"> </param>
public void RunAppAndWait(string appPath, string args)
{
System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo();
//
Info.FileName = appPath;
Info.Arguments = args;
//
System.Diagnostics.Process Proc;
try
{
this.Hide();
Proc = System.Diagnostics.Process.Start(Info);
Proc.WaitForExit();
}
catch (System.ComponentModel.Win32Exception)
{
this.Show();
return;
}
this.Show();
}
private void btnRunProcess_Click(object sender, EventArgs e)
{
RunAppAndWait(txtApp.Text, txtArgs.Text);
}
private void FormMain_Load(object sender, EventArgs e)
{
txtApp.Text = Application.StartupPath + "\\app.exe";
txtArgs.Text = " abc";
}
private void btnStart_Click(object sender, EventArgs e)
{
System.Diagnostics.Process[] procs = System.Diagnostics.Process.GetProcessesByName(txtProcess.Text);
if (procs.Length > 0)
{
foreach (System.Diagnostics.Process item in procs)
{
item.EnableRaisingEvents = true;
item.Exited += new EventHandler(item_Exited);
}
}
}
public delegate void MyInvoke(string str);
private void SetText(string s)
{
if (txtStatus.InvokeRequired)
{
MyInvoke _myInvoke = new MyInvoke(SetText);
this.Invoke(_myInvoke, new object[] { s });
}
else
{
this.txtStatus.AppendText(s);
}
}
void item_Exited(object sender, EventArgs e)
{
var p = sender as System.Diagnostics.Process;
SetText(p.ProcessName + " ");
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Asp와 XML로 상호작용하는 실례 원본XML은 표준 확장 언어로 미래 웹 프로그래밍의 표준이다. asp는 현재 널리 전해지는 웹 프로그래밍 언어 중의 하나이다. 그들 두 사람이 연합하여 역할을 발휘할 수 있을까?두부는 여기서 여러분에게 아주 간단한 As...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.