DNS刷新超时使用Mono [英] DNS Refresh Timeout with Mono

查看:351
本文介绍了DNS刷新超时使用Mono的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然当前项目的 ServicePointManager 类有 DnsRefreshTimeout 启用到它的接口属性。该相关的属性不落实

Although the current Mono project's ServicePointManager class has the DnsRefreshTimeout property enabled into its interface. The related property isn't implemented.

样品电话:

ServicePointManager.DnsRefreshTimeout = 10*60*1000; // 10 minutes

在运行我的应用程序得到运行下一个异常:

When running my application I get the next exception on runtime:

The requested feature is not implemented. (System.NotImplementedException) at System.Net.ServicePointManager.set_DnsRefreshTimeout (Int32 value) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/ServicePointManager.cs:213

下面是实际执行:

[MonoTODO]
public static int DnsRefreshTimeout
{
    get {
        throw GetMustImplement ();
    }
    set {
        throw GetMustImplement ();
    }
}



我觉得我没有足够的知识来实现这个功能都是由我自己,只是因为我正在开发自上个月C#的Mono应用。

I think I don't have enough knowledge to implement this feature all by myself just because I am developing C# Mono applications since last month.

那么,任何人都知道这一个解决方法吗?或应我请求Mono项目团队功能实现?

So, do anyone know one workaround for this? Or shall I request a feature implementation for the Mono project team?

我开发一个Xamarin跨平台应用程序,我真的需要缓存我的DNS解析至少10分钟。

I am developing a Xamarin cross-platform application and I really need to cache my DNS resolution at least for 10 minutes.

诗功能要求在 https://bugzilla.xamarin.com/show_bug.cgi?id=11424

推荐答案

我没有一个解决方法,但我有一个解决方法:

I don't have a fix, but I have a workaround:

var request = (HttpWebRequest)WebRequest.Create("http://www.google.com/");

// Disable KeepAlive so we don't reuse  connections
request.KeepAlive = false;

// Clear out the cached host entry
var hostField     = typeof(ServicePoint).GetField("host", BindingFlags.NonPublic | BindingFlags.Instance);
var hostFieldLock = typeof(ServicePoint).GetField("hostE", BindingFlags.NonPublic | BindingFlags.Instance);
var hostLock      = hostFieldLock.GetValue(request.ServicePoint);
lock (hostLock)
    hostField.SetValue(request.ServicePoint, null);

这是基于当前版本的ServicePoint为单声道,您可以查看的这里为2015年3月的

This is based on the current version of ServicePoint for mono which you can view here as of March 2015.

这篇关于DNS刷新超时使用Mono的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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