Exemple #1
0
        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);
        }
Exemple #2
0
        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;
        }