System.Collections.Concurrent.ConcurrentBag.Add(System.Func)

Here are the examples of the csharp api class System.Collections.Concurrent.ConcurrentBag.Add(System.Func) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

1. Example

Project: a-vs-an
Source File: Program.cs
static Task<Node> BuildAvsAnTrie(BlockingCollection<AvsAnSighting[]> entriesTodo)
        {
            var wordCount = 0;

            var sw = Stopwatch.StartNew();
            ProgressReporters.Add(() => "words/ms: " + (wordCount / sw.Elapsed.TotalMilliseconds).ToString("f1"));

            var trieBuilder = Task.Factory.StartNew(
                () => {
                    var trie = new Node();
                    foreach (var entries in entriesTodo.GetConsumingEnumerable())
                    foreach (var entry in entries) {
                        IncrementPrefixExtensions.IncrementPrefix(ref trie, entry.PrecededByAn, entry.Word, 0);
                        wordCount++;
                    }
                    return trie;
                },
                TaskCreationOptions.LongRunning);
            return trieBuilder;
        }

2. Example

Project: a-vs-an
Source File: Program.cs
static BlockingCollection<AvsAnSighting[]> ExtractAvsAnSightingsAsync(BlockingCollection<string[]> wikiPageQueue)
        {
            var entriesTodo = new BlockingCollection<AvsAnSighting[]>(SightingBlocksQueueSize);
            ProgressReporters.Add(() => "wordQ: " + entriesTodo.Count);

            var sightingExtractionTask = Task.WhenAll(
                Enumerable.Range(0, Environment.ProcessorCount)
                    .Select(
                        i =>
                            Task.Factory.StartNew(
                                () => {
                                    var ms = new RegexTextUtils();
                                    foreach (var pageSet in wikiPageQueue.GetConsumingEnumerable())
                                    foreach (var page in pageSet)
                                        entriesTodo.Add(ms.FindAvsAnSightings(page));
                                },
                                TaskCreationOptions.LongRunning)
                    )
                    .ToArray()
            );

            sightingExtractionTask.ContinueWith(
                t => {
                    if (t.IsFaulted)
                        Console.WriteLine(t.Exception);
                    entriesTodo.CompleteAdding();
                });
            return entriesTodo;
        }

3. Example

Project: a-vs-an
Source File: Program.cs
static BlockingCollection<string[]> LoadWikiPagesAsync(string wikiPath)
        {
            /n ..... /n //View Source file for more details /n }