我是一个初学者,不知道错在哪listbox上不显示信息。请高手们看看
public class getFf
{
public DirectoryInfo dds;
public getFf(DirectoryInfo fs)
{
this.dds = fs;
}
public void ThreadF()
{
if (dds != null)
{
try
{
filePathShow fps = new filePathShow();
fps.WalkDirectoryTree(dds); }
catch (Exception)
{
throw;
}
}
}
}
private void btnStart_Click(object sender, EventArgs e)
{
//Control.CheckForIllegalCrossThreadCalls = false;
DriveInfo[] di = DriveInfo.GetDrives();
foreach (DriveInfo dri in di)
{
if (dri.IsReady)
{
if (dri.Name != @"C:\")
{
try
{
DirectoryInfo dInfo = dri.RootDirectory;
WalkDirectoryTree(dInfo);
getFf gf = new getFf(dInfo);
Thread thread = new Thread(new ThreadStart(gf.ThreadF)); thread.Start();
//WalkDirectoryTree(dba);
}
catch (Exception)
{
throw;
}
}
}
}
} public void WalkDirectoryTree(DirectoryInfo root)
{ FileInfo[] files = null;
DirectoryInfo[] subDirs = null; try
{
files = root.GetFiles("*.*");
}
catch (UnauthorizedAccessException e)
{ } if (files != null)
{
foreach (System.IO.FileInfo fi in files)
{
//在listbox上显示
lbxShow.Items.Add(fi.FullName);
lbxShow.Items.Add(fi.Name);
} subDirs = root.GetDirectories(); foreach (System.IO.DirectoryInfo dirInfo in subDirs)
{
WalkDirectoryTree(dirInfo);
}
}
}
}
public class getFf
{
public DirectoryInfo dds;
public getFf(DirectoryInfo fs)
{
this.dds = fs;
}
public void ThreadF()
{
if (dds != null)
{
try
{
filePathShow fps = new filePathShow();
fps.WalkDirectoryTree(dds); }
catch (Exception)
{
throw;
}
}
}
}
private void btnStart_Click(object sender, EventArgs e)
{
//Control.CheckForIllegalCrossThreadCalls = false;
DriveInfo[] di = DriveInfo.GetDrives();
foreach (DriveInfo dri in di)
{
if (dri.IsReady)
{
if (dri.Name != @"C:\")
{
try
{
DirectoryInfo dInfo = dri.RootDirectory;
WalkDirectoryTree(dInfo);
getFf gf = new getFf(dInfo);
Thread thread = new Thread(new ThreadStart(gf.ThreadF)); thread.Start();
//WalkDirectoryTree(dba);
}
catch (Exception)
{
throw;
}
}
}
}
} public void WalkDirectoryTree(DirectoryInfo root)
{ FileInfo[] files = null;
DirectoryInfo[] subDirs = null; try
{
files = root.GetFiles("*.*");
}
catch (UnauthorizedAccessException e)
{ } if (files != null)
{
foreach (System.IO.FileInfo fi in files)
{
//在listbox上显示
lbxShow.Items.Add(fi.FullName);
lbxShow.Items.Add(fi.Name);
} subDirs = root.GetDirectories(); foreach (System.IO.DirectoryInfo dirInfo in subDirs)
{
WalkDirectoryTree(dirInfo);
}
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货