首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ServicePointManager.FindServicePoint块

ServicePointManager.FindServicePoint块
EN

Stack Overflow用户
提问于 2019-03-14 21:48:14
回答 1查看 107关注 0票数 0

我正在调用这个方法:

代码语言:javascript
复制
ServicePoint sp = ServicePointManager.FindServicePoint(mRequest.RequestUri, this.MapDataWebProxy);

用于获取服务点,但当没有可用的internet连接时,该方法就不会返回。

关于如何防止这种情况或设置超时,您有什么建议吗?

EN

回答 1

Stack Overflow用户

发布于 2019-03-14 22:11:27

您可以尝试在调用该方法之前验证Internet连接。它可以像这样做:

代码语言:javascript
复制
[DllImport("wininet.dll")]
    private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);

    //Creating a function that uses the API function...
    public static bool IsConnectedToInternet()
    {
        int Desc;
        return InternetGetConnectedState(out Desc, 0);
    }

    public ServicePoint GetServicePoint()
    {
        if (!IsConnectedToInternet())
        {
            return null;
        }
        return ServicePointManager.FindServicePoint(mRequest.RequestUri, this.MapDataWebProxy);
    }

此外,还可以用另一种方式检查互联网。不使用"wininet.dll“库:What is the best way to check for Internet connectivity using .NET?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55164207

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档