private void button1_Click(object sender, EventArgs e)
{
Thread th = new Thread(add);
th.Start();
}
public void add ()
{
del d = add;//委托
DirectoryInfo di =new DirectoryInfo(@"F:\新建文件夹");
foreach (FileInfo f in di.GetFiles())
{
if (listBox1.InvokeRequired)
{
listBox1.Invoke(d);
}
else
{
this.listBox1.Items.Add(f.Name);
}
}
}
就是想遍历一下F:\新建文件夹 的文件。。 但我这样 写,为什么会重复遍历3次呢。 怎么控制线程只遍历一次。
{
Thread th = new Thread(add);
th.Start();
}
public void add ()
{
del d = add;//委托
DirectoryInfo di =new DirectoryInfo(@"F:\新建文件夹");
foreach (FileInfo f in di.GetFiles())
{
if (listBox1.InvokeRequired)
{
listBox1.Invoke(d);
}
else
{
this.listBox1.Items.Add(f.Name);
}
}
}
就是想遍历一下F:\新建文件夹 的文件。。 但我这样 写,为什么会重复遍历3次呢。 怎么控制线程只遍历一次。
listBox1.Invoke(d);