虽然目前Mono
项目的ServicePointManager
类有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 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 for mono,您可以查看here https://github.com/mono/mono/blob/master/mcs/class/System/System.Net/ServicePoint.cs截至 2015 年 3 月。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)