gpt4 book ai didi

c# - 单声道的 DNS 刷新超时

转载 作者:太空宇宙 更新时间:2023-11-03 11:06:37 26 4
gpt4 key购买 nike

尽管当前 Mono 项目的 ServicePointManager 类在其接口(interface)中启用了 DnsRefreshTimeout 属性。相关属性未实现。

示例调用:

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

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

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 应用程序。

那么,有人知道解决这个问题的方法吗?或者我应该为 Mono 项目团队请求功能实现吗?

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

附言在 https://bugzilla.xamarin.com/show_bug.cgi?id=11424 请求的功能

最佳答案

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

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,您可以查看 here截至 2015 年 3 月。

关于c# - 单声道的 DNS 刷新超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15643223/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com