コード例 #1
0
ファイル: Program.cs プロジェクト: thesearchparty/a-vs-an
        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);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: EamonNerbonne/a-vs-an
        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;
        }