DIrectoryInfo.Attributes挂起很长时间(15分钟) [英] DIrectoryInfo.Attributes hanging for a long time (15 minutes)

查看:102
本文介绍了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文件夹浏览器 [





WPF Folder Browser[^]

Thanks in advance.
Erik

推荐答案

那么,我建议的第一件事就是让嗅探器运行.挑战/响应超时可能很简单,在这种情况下,您会努力增加时间,以便在足够的时间内获得响应.

它还可能显示您是否收到碎片化的数据包或其他与路由器或基础结构有关的与网络有关的问题.

有时,您在环境中别无选择,这是您可以在后台进行修复的问题.一年来,我参加了Tech Ed的一场大型讨论,主题是与南美洲一家分支机构的卫星通信.那是一个bug,因为传输和回传每种方式都增加了1秒!

您可能能够通过嗅探器跟踪解决足够的问题,然后在需求中建立最小值,例如质询响应超时,数据包大小等.不幸的是,DirectoryInfo不包含(我知道)任何种类的超时设置,因为它依赖于堆栈.
The first thing I would suggest, then, is to get the sniffer trace run. It could be something as simple as challenge/response timing out, in which case you work to get the timing increased so you get the response back in enough time.

It may also show you if you are getting fragmented packets or other network related issues that can be fixed with with routers or infrastructure.

Sometimes you have no choice in your environment and it is a matter of what you can do in the background to fix it. I sat in on a huge discussion at Tech Ed one year on the subject of satellite communication to a branch in South America. That was a bugger because the transmit up and back add 1 second each way!!

You may be able to get enough issues resolved via the sniffer trace that you can then establish a minimum in your requirements such as challenge-response timeout, packet size, etc. Unfortunately, DirectoryInfo does not incorporate (that I know of) any kind of timeout settings as it relies on the stack for that.


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆