B
Berk
Hello,
I have a asyncronuos directory traverser program. My problem is, after
changing the hard drive it traverses, it keeps traversing the previous
drive, not the current drive. I'm putting here the source code for an
advice, probably needs a thread synhronization:
public delegate void WalkDirectoryProc(string directory);
public System.IAsyncResult BeginWalkDirectory(string directory,
AsyncCallback callback)
{
WalkDirectoryProc walkDirCallback = new
WalkDirectoryProc(WalkDirectory);
return walkDirCallback.BeginInvoke(directory, callback, null);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void WalkDirectory(DirectoryInfo directoryInfo)
{
FileSystemInfo[] fsis =
directoryInfo.GetFileSystemInfos();
try
{
foreach (FileInfo file in directoryInfo.GetFiles())
{
RaiseFileEvent(file);
}
//}
}
catch (InvalidOperationException ioex)
{
Debug.WriteLine(ioex.Message);
throw ioex;
}
catch (UnauthorizedAccessException)
{
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
DirectoryInfo[] subDirectories =
directoryInfo.GetDirectories();
foreach (DirectoryInfo subDirectory in subDirectories)
{
WalkDirectory(subDirectory);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void scanDirectory_FileEvent(object sender, FileEventArgs e)
{
if (_bufList.Count >= _bufList.Capacity)
{
for (int i = 0; i < 20 - 1; ++i)
listViewContentList.Invoke(new
CrossThreadHandler(delegate() {
listViewContentList.Items.Add(_bufList.No.ToString()).SubItems.AddRange(new
string[] {
_bufList.Name, _bufList.ParentDirName
}
);
}
));
_bufList.Clear();
}
FilenameHelper helper = new FilenameHelper();
helper.No = _fileCount++;
helper.Name = e.Info.Name;
helper.ParentDirName = e.Info.Directory.Name;
_bufList.Add(helper);
}
Regards.
I have a asyncronuos directory traverser program. My problem is, after
changing the hard drive it traverses, it keeps traversing the previous
drive, not the current drive. I'm putting here the source code for an
advice, probably needs a thread synhronization:
public delegate void WalkDirectoryProc(string directory);
public System.IAsyncResult BeginWalkDirectory(string directory,
AsyncCallback callback)
{
WalkDirectoryProc walkDirCallback = new
WalkDirectoryProc(WalkDirectory);
return walkDirCallback.BeginInvoke(directory, callback, null);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void WalkDirectory(DirectoryInfo directoryInfo)
{
FileSystemInfo[] fsis =
directoryInfo.GetFileSystemInfos();
try
{
foreach (FileInfo file in directoryInfo.GetFiles())
{
RaiseFileEvent(file);
}
//}
}
catch (InvalidOperationException ioex)
{
Debug.WriteLine(ioex.Message);
throw ioex;
}
catch (UnauthorizedAccessException)
{
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
DirectoryInfo[] subDirectories =
directoryInfo.GetDirectories();
foreach (DirectoryInfo subDirectory in subDirectories)
{
WalkDirectory(subDirectory);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void scanDirectory_FileEvent(object sender, FileEventArgs e)
{
if (_bufList.Count >= _bufList.Capacity)
{
for (int i = 0; i < 20 - 1; ++i)
listViewContentList.Invoke(new
CrossThreadHandler(delegate() {
listViewContentList.Items.Add(_bufList.No.ToString()).SubItems.AddRange(new
string[] {
_bufList.Name, _bufList.ParentDirName
}
);
}
));
_bufList.Clear();
}
FilenameHelper helper = new FilenameHelper();
helper.No = _fileCount++;
helper.Name = e.Info.Name;
helper.ParentDirName = e.Info.Directory.Name;
_bufList.Add(helper);
}
Regards.