public delegate void FileEventHandler(string file);
public event FileEventHandler fileEvent;
public void getAllFiles(string path)
{
foreach (string item in Directory.GetDirectories(path))
{
try
{
getAllFiles(item);
}
catch (Exception)
{ }
}
foreach (string str in Directory.GetFiles(path, "*.pcap"))
{
// process my file and if this file format OK raised event to UI and add the file to my listbox
FileChecker fileChecker = new FileChecker();
string result = fileChecker.checkFIle(str);
if (result != null)
fileEvent(result);
}
}
private void btnAddDirInput_Click(object sender, EventArgs e)
{
ThreadStart ts = delegate { getAllFiles(pathToSearch); };
Thread thread = new Thread(ts);
thread.IsBackground = true;
thread.Start();
}
我想等到线程完成自己的工作,然后更新我的UI等到我的线程完成
你的线程在哪里? – CodingIntrigue
http://stackoverflow.com/questions/1584062/how-to-wait-for-thread-to-finish-with-net?rq=1检查出来 – Nick
我通过邮件中的另一个线程调用getAllFiles() UI – user2214609