本文整理汇总了C#中ConcurrentDictionary.Count方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentDictionary.Count方法的具体用法?C# ConcurrentDictionary.Count怎么用?C# ConcurrentDictionary.Count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConcurrentDictionary
的用法示例。
在下文中一共展示了ConcurrentDictionary.Count方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Queue_WithHighThreadCount_WorksCorrectly
public void Queue_WithHighThreadCount_WorksCorrectly(int threads, int enqueues, int dequeues)
{
//The elements we insert are unique and sentinel value is -1
int initialValue = -1;
int currentValue = initialValue;
ConcurrentDictionary<int, int> table = new ConcurrentDictionary<int, int>();
Core.Queue.Queue<int> queue = new Core.Queue.Queue<int>(initialValue);
ThreadBuilder
.Empty()
.AddThreads(() =>
{
for (int i = 0; i < enqueues; i++)
{
int value = Interlocked.Increment(ref currentValue);
queue.Enqueue(value);
}
}, threads)
.AddThreads(() =>
{
for (int i = 0; i < dequeues; i++)
{
int value = queue.Dequeue();
table.AddOrUpdate(value, x => 1, (k, v) => v + 1);
}
}, threads)
.Start();
//The sentinel value can be returned more than once if queue is empty at the time of a pop
int expectedPops = table.Keys.Count + (table.ContainsKey(initialValue) ? -1 : 0);
int actualPops = table.Count(x => x.Key != initialValue && x.Value == 1);
Assert.AreEqual(expectedPops, actualPops);
}
示例2: List_WithHighThreadCount_WorksCorrectly
public void List_WithHighThreadCount_WorksCorrectly(int threads, int adds, int removes)
{
//The elements we insert are unique and sentinel value is -1
int initialValue = -1;
int currentValue = initialValue;
ConcurrentDictionary<int, int> table = new ConcurrentDictionary<int, int>();
Core.List.List<int> list = new Core.List.List<int>(initialValue);
Random random = new Random();
ThreadBuilder
.Empty()
.AddThreads(() =>
{
for (int i = 0; i < adds; i++)
{
int value = Interlocked.Increment(ref currentValue);
list.Add(value);
}
}, threads)
.AddThreads(() =>
{
for (int i = 0; i < removes; i++)
{
int element = random.Next(currentValue);
if (table.ContainsKey(element))
{
list.Remove(element);
table.AddOrUpdate(element, x => 1, (k, v) => v + 1);
}
}
}, threads)
.Start();
//The sentinel value can be returned more than once if queue is empty at the time of a dequeue
int expectedAdds = table.Keys.Count + (table.ContainsKey(initialValue) ? -1 : 0);
int actualRemoves = table.Count(x => x.Key != initialValue && x.Value == 1);
Assert.AreEqual(expectedAdds, actualRemoves);
}
示例3: GetLocalOnlyAnsiCharacters
private Dictionary<string, bool> GetLocalOnlyAnsiCharacters(Dictionary<string, int> tfsEncodings)
{
var bag = new ConcurrentDictionary<string, bool>();
Console.WriteLine("Checking if local files are using non-ANSI characters...");
Parallel.ForEach(
tfsEncodings,
item =>
{
var filePath = Path.Combine(Args.ProjectPath, item.Key);
bag[item.Key] = IsUsingOnlyAnsiCharacters(filePath, item.Value);
});
Console.WriteLine("Checked {0} local files, {1} are using non-ANSI characters.", bag.Count, bag.Count(i => !i.Value));
return bag.ToDictionary(i => i.Key, i => i.Value);
}
示例4: GetLocalUtf8BomSignatures
private Dictionary<string, bool> GetLocalUtf8BomSignatures(IEnumerable<string> textFiles)
{
var bag = new ConcurrentDictionary<string, bool>();
Console.WriteLine("Checking if local files are using UTF-8 signatures...");
Parallel.ForEach(
textFiles,
file =>
{
var filePath = Path.Combine(Args.ProjectPath, file);
bag[file] = IsUsingUtf8BomSignature(filePath);
});
Console.WriteLine("Checked {0} local files, {1} are using UTF-8 signatures.", bag.Count, bag.Count(i => i.Value));
return bag.ToDictionary(i => i.Key, i => i.Value);
}
示例5: InitRealms
private void InitRealms()
{
this.realms = loadRealms();
var flat =
from realm in realms
from rgroup in realm.groups
from location in rgroup.Locations
from person in location.People
select new Tuple<IndexKey, Person>(
new IndexKey(realm.RealmName, rgroup.GroupName, location.LocationName, person.Name),
person);
log.InfoFormat("flat {0}", flat.Count());
this.peopleIndex = new ConcurrentDictionary<IndexKey,Person>(flat.ToDictionary(
(realmKey) => realmKey.Item1,
(realmValue) => realmValue.Item2));
log.InfoFormat("index {0}", peopleIndex.Count());
foreach (var item in peopleIndex)
{
log.InfoFormat("index {0} {1}", item.Key, item.Value.Name);
}
}
示例6: Run
/// <summary>
///
/// </summary>
/// <param name="Start"></param>
/// <param name="Stop">We just truncate VA's at 48 bit's</param>
/// <returns>count of new detections since last Run</returns>
public long Run(long Start=0, long Stop = 0xFFFFffffFFFF)
{
DetectedFragments = new ConcurrentDictionary<long, VAScanType>();
// convert index to an address
// then add start to it
long i = Start;
var block = new long[0x200]; // 0x200 * 8 = 4k
while (i < Stop)
{
foreach (var scanner in CheckMethods)
{
HARDWARE_ADDRESS_ENTRY locPhys = HARDWARE_ADDRESS_ENTRY.MinAddr;
if (DPContext.vmcs != null)
//locPhys = MemoryBank[j].VirtualToPhysical(DPContext.vmcs.EPTP, DPContext.CR3Value, i);
locPhys = BackingBlocks.VirtualToPhysical(DPContext.vmcs.EPTP, DPContext.CR3Value, i);
else
//locPhys = MemoryBank[j].VirtualToPhysical(DPContext.CR3Value, i);
locPhys = BackingBlocks.VirtualToPhysical(DPContext.CR3Value, i);
var Curr = i;
i += 0x1000;
if (HARDWARE_ADDRESS_ENTRY.IsBadEntry(locPhys))
continue;
bool GotData = false;
BackingBlocks.GetPageForPhysAddr(locPhys, ref block, ref GotData);
if (!GotData)
continue;
var scan_detect = scanner(Curr, block);
if (scan_detect != VAScanType.UNDETERMINED)
{
DetectedFragments.TryAdd(Curr, scan_detect);
if (Vtero.VerboseOutput)
Console.WriteLine($"Detected PE @ VA {Curr:X}");
}
}
}
return DetectedFragments.Count();
}
示例7: GetPageHtml
public void GetPageHtml(ConcurrentDictionary<int, HtmlNode> vehiclePageLinks, ConcurrentDictionary<string, HtmlDocument> vehicleWikiPagesContent)
{
foreach (var vehiclePageLink in vehiclePageLinks)
{
// Remove the current node so that the other threads don't reprocess it
HtmlNode tempNode;
vehiclePageLinks.TryRemove(vehiclePageLink.Key, out tempNode);
// Fetch page information
HtmlNode linkNode = vehiclePageLink.Value;
string wikiRelativeUrl = linkNode.Attributes.Single(l => l.Name == "href").Value;
string vehicleWikiEntryFullUrl = new Uri(new Uri(ConfigurationManager.AppSettings["BaseWikiUrl"]), wikiRelativeUrl).ToString();
string vehicleName = linkNode.InnerText;
// Write out the vehicle name and url
_consoleManager.WriteBlankLine();
_consoleManager.WriteTextLine($"Processing... {vehicleName}");
_consoleManager.WriteTextLine($"Vehicle: {vehicleName}, Url: {vehicleWikiEntryFullUrl}");
// Visit page and extract data
HtmlWeb vehicleWebGet = new HtmlWeb();
HtmlDocument vehicleWikiPage = vehicleWebGet.Load(vehicleWikiEntryFullUrl);
// Add page to new dictionary used to extract further data
vehicleWikiPagesContent.TryAdd(vehicleName, vehicleWikiPage);
_consoleManager.WriteTextLine(vehicleWikiPagesContent.Count().ToString());
}
}
示例8: SetupAppProcesses
private static ConcurrentDictionary<string, AppProcess> SetupAppProcesses(ProcessControlConfiguration serverConfig)
{
var appServers = new ConcurrentDictionary<string, AppProcess>();
foreach (var val in serverConfig.ProcessInstances)
{
AppProcess module = SetupAppProcess(val);
if (module != null)
{
string guid = module.ProcessGuid;
appServers.TryAdd(guid, module);
}
}
logger.DebugFormat("Setup [{0}] worker processes.", appServers.Count());
return appServers;
}