如何等待一个进程结束???

ivan10000 2008-04-15 03:00:06
比如一个WinRAR进程在运行,该如何判断WinRAR进程是否结束,若WinRAR不结束则等待,直到WinRAR进程结束才继续下面的操作。
谢谢
...全文
422 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
changjiangzhibin 2008-04-15
  • 打赏
  • 举报
回复
sign
zp_cool 2008-04-15
  • 打赏
  • 举报
回复
namespace FileSystemWatcherExample
{
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{


// Create a new FileSystemWatcher and set its properties.
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = "E:\\Project\\C#组件熟悉\\窗体控件\\FileSystemWatcherExample";

/* Watch for changes in LastAccess and LastWrite times, and
the renaming of files or directories. */

watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Only watch text files.
watcher.Filter = "test.txt";

// Add event handlers.
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);


// Begin watching.
watcher.EnableRaisingEvents = true;
// Wait for the user to quit the program.

}
// Define the event handlers.
private static void OnChanged(object source, FileSystemEventArgs e)
{
// Specify what is done when a file is changed, created, or deleted.
MessageBox.Show("File: " + e.FullPath + " " + e.ChangeType);
}

private static void OnRenamed(object source, RenamedEventArgs e)
{
// Specify what is done when a file is renamed.

MessageBox.Show("File:" + e.OldFullPath + "renamed to" + e.FullPath);
}

}
}
jinjazz 2008-04-15
  • 打赏
  • 举报
回复
 System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "mspaint";
p.Start();
p.WaitForExit();
MessageBox.Show("");
ivan10000 2008-04-15
  • 打赏
  • 举报
回复

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧