第一个疑惑的问题是关于IIS服务器的会话的,一台服务器的IIS 6.0昨天访问,发现会话在20秒左右就会丢失,而这个程序没有修改,也没有修改什么配置,检查一天无果。
最后发现服务器时间是2005年1月1日,少了近30天,修改后一切正常,
有哪位高人解释一下原理。
今天写程序,写到这里
if ( serviceProviders.Contains(serviceProvider) )
serviceProviders.Remove(serviceProvider);
感觉有些浪费,俩次查找定位,这让我突然有兴趣看看范型实现的内部代码(我的这个集合使用的List<>)
private List<IServiceProvider> serviceProviders = new List<IServiceProvider>();
使用Reflector反编译工具查看其实现
public bool Contains(T item)
{
if (item == null)
{
for (int num1 = 0; num1 < this._size; num1++)
{
if (this._items[num1] == null)
{
return true;
}
}
return false;
}
IComparer<T> comparer1 = Comparer<T>.Default;
for (int num2 = 0; num2 < this._size; num2++)
{
if (comparer1.Equals(item, this._items[num2]))
{
return true;
}
}
return false;
}
我倒
这个效率 …… 怎么说你也用个 Hash冒个泡吧。
后来,看了一下IndexOf,是调用数组的,但一看数组,也是一样的实现。
经过非常“深刻”的思考,哦,是自己使用不当,如果想通过 key 查找,用 System.Collections.Generic.Dictionary<K,V>最好,看看实现吧
最后发现服务器时间是2005年1月1日,少了近30天,修改后一切正常,

今天写程序,写到这里




使用Reflector反编译工具查看其实现

























我倒

后来,看了一下IndexOf,是调用数组的,但一看数组,也是一样的实现。
经过非常“深刻”的思考,哦,是自己使用不当,如果想通过 key 查找,用 System.Collections.Generic.Dictionary<K,V>最好,看看实现吧
private int FindEntry(K key) { if (key == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); } if (this.buckets != null) { int num1 = this.comparer.GetHashCode(key) & 0x7fffffff; for (int num2 = this.buckets[num1 % this.buckets.Length]; num2 >= 0; num2 = this.entries[num2].next) { if ((this.entries[num2].hashCode == num1) && this.comparer.Equals(key, this.entries[num2].key)) { return num2; } } } return -1; }
· MySQL下200GB大表备份,利用传输表空间解决停服发版表备份问题
· 记一次 .NET某固高运动卡测试 卡慢分析
· 微服务架构学习与思考:微服务拆分的原则
· 记一次 .NET某云HIS系统 CPU爆高分析
· 如果单表数据量大,只能考虑分库分表吗?
· 7 个最近很火的开源项目「GitHub 热点速览」
· DeepSeekV3:写代码很强了
· 记一次 .NET某固高运动卡测试 卡慢分析
· Visual Studio 2022 v17.13新版发布:强化稳定性和安全,助力 .NET 开发提
· MySQL下200GB大表备份,利用传输表空间解决停服发版表备份问题