本文整理汇总了C#中ConcurrentDictionary.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentDictionary.GetEnumerator方法的具体用法?C# ConcurrentDictionary.GetEnumerator怎么用?C# ConcurrentDictionary.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConcurrentDictionary
的用法示例。
在下文中一共展示了ConcurrentDictionary.GetEnumerator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChannelFactory
public ChannelFactory(RawRabbitConfiguration config, IConnectionFactory connectionFactory)
{
_connectionFactory = connectionFactory;
_accessDictionary = new ConcurrentDictionary<IModel, DateTime>();
_config = config;
_threadChannels = new ThreadLocal<IModel>(true);
try
{
_logger.LogDebug("Connecting to primary host.");
_connection = _connectionFactory.CreateConnection(_config.Hostnames);
_logger.LogInformation("Successfully established connection.");
}
catch (BrokerUnreachableException e)
{
_logger.LogError("Unable to connect to broker", e);
throw e.InnerException;
}
_closeTimer = new System.Threading.Timer(state =>
{
var enumerator = _accessDictionary.GetEnumerator();
while (enumerator.MoveNext())
{
if (DateTime.Now - enumerator.Current.Value > _config.RequestTimeout)
{
DateTime lastUsed;
if (_accessDictionary.TryRemove(enumerator.Current.Key, out lastUsed))
{
_logger.LogInformation($"Channel {enumerator.Current.Key.ChannelNumber} was last used {lastUsed}. Closing...");
enumerator.Current.Key.Close();
}
}
}
}, null, _config.RequestTimeout, _config.RequestTimeout);
}
示例2: GetEnumerator_ThrowsNotImplementedException
public void GetEnumerator_ThrowsNotImplementedException()
{
// Arrange
ConcurrentDictionary<int, int> dictionary = new ConcurrentDictionary<int, int>();
// Act/Assert
Assert.Throws<NotImplementedException>(() => dictionary.GetEnumerator());
}