识别网络路径存在的最快方法 [英] Fastest way to identify Network Path Exists

查看:68
本文介绍了识别网络路径存在的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我需要搜索网络路径并根据文件夹的存在进行一些处理.让我们举个例子,我必须在网络上搜索路径,如果路径存在,我必须启用一些控件,否则我需要禁用这些控件.我尝试使用 DirectoryInfo 对象并获得正确的值:

In my application I need to search for a network path and do some processing based on the existence of the folder. Let us take an example, I have to search for a path on network and if path exists I have to enable some controls otherwise I need to disable the controls. I tried using DirectoryInfo object and getting the correct values:

    DirectoryInfo dirInfo = new DirectoryInfo(@"\ServerIPAddress\FolderName");

    if(dirInfo.Exists)
    {
            //do something
    }
    else
    {
           //do something else
    }

上述代码的问题是获取 Exists 属性需要花费超过 2 分钟的时间.

The problem with the above code is it is consuming more than 2 minutes for getting the Exists property.

有没有更快的方法来检查网络路径是否存在.

Is there any faster way to check for network path existence.

谢谢和问候,
阿什·夏尔马

Thanks and regards,
Ashish Sharma

推荐答案

通常只有在指定路径中不存在文件夹时,这才需要时间.您可以使用不同的线程来检查此处描述的文件夹的存在(以及代表):如何在 GetFileAttributes 中避免网络停顿?

Usually this would take time only if the folder does not exist in the specified path. You could use a different thread to check the existence of the folder as described here (along with delegates): How to avoid network stalls in GetFileAttributes?

您也可以查看此相关问题:如何:在检查不可用的网络共享时防止超时 - C#

Also you can check this related question: How To: Prevent Timeout When Inspecting Unavailable Network Share - C#

这篇关于识别网络路径存在的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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