本文介绍了DIrectoryInfo.Attributes挂起很长时间(15分钟)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我一直在修改WPF文件夹浏览器,以通过引入几个新功能来增强它.在这项工作中,我遇到了一个与DirectoryInfo.Attributes有关的奇怪问题,该属性对于我们网络上的某个文件夹无法快速响应.

简而言之,我要做的是检查所有文件夹是否被隐藏-在这种情况下,我不会尝试加载它们.一个文件夹花了大约15分钟来回复.我对该文件夹不是特别感兴趣,而是对将响应返回给用户更感兴趣.我应该如何处理此问题?
下面列出的代码带有文章链接:

Hi,
I''ve been tinkering with the WPF Folder Browser to enhance it by introducing a couple of new features. During this work I ran into a curious issue with DirectoryInfo.Attributes that failed to respond quickly for a certain folder on our network.

What I do in short is checking all folders if they are hidden - in which case I don''t attempt to load them. One folder took about 15 minutes to respond. I am not particularly interested in this folder, more interested in getting a response back to the user. What should my approach to this problem be?
The code listed below with a link to the article:

private void LoadFolders()
{
    try
    {
        if (Folders.Count > 0)
            return;
        string[] dirs = null;
        string fullPath = Path.Combine(FolderPath, FolderName);
        var bDrive = FolderName.Contains(':');
        if (FolderName.Contains(':'))//This is a drive
        {
            fullPath = string.Concat(FolderName, @"\");
        }
        else
        {
            fullPath = FolderPath;
        }
        dirs = Directory.GetDirectories(fullPath);
        Folders.Clear();
        foreach (string dir in dirs)
        {
            try
            {
                DirectoryInfo di = new DirectoryInfo(dir);
                // create the sub-structure only if this is not a hidden directory
                //TODO hack SORT OUT THIS WAITING BUSINESS - For some reason this path doesn't answer di.Attributes for 15 minutes?!?
                if (dir.StartsWith("P:\\USAUS")) continue;
                //WORK AROUND Line below - (when a full path is pasted into the text box - only expand the actual path (or as much of it as possible)
                if (!(Root.SelectedFolder.StartsWith(dir) || System.IO.Path.GetDirectoryName(dir) == (Root.SelectedFolder + (bDrive ? @"\" : "")))) continue;
                if ((di.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
                {
                    Folders.Add(new FolderViewModel
                                    {
                                        Root = this.Root,
                                        FolderName = Path.GetFileName(dir),
                                        FolderPath = Path.GetFullPath(dir),
                                        FolderIcon = "Images\\FolderClosed.png"
                                    });
                }
            }
            catch (UnauthorizedAccessException ae)
            {
                Console.WriteLine(ae.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        if (FolderName.Contains(":"))
            FolderIcon = "Images\\HardDisk.ico";
    }
    catch (UnauthorizedAccessException ae)
    {
        Console.WriteLine(ae.Message);
    }
    catch (IOException ie)
    {
        Console.WriteLine(ie.Message);
    }
}





WPF文件夹浏览器 [ ^ ]

提前谢谢.
Erik





WPF Folder Browser[^]

Thanks in advance.
Erik

推荐答案


这篇关于DIrectoryInfo.Attributes挂起很长时间(15分钟)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 20:23