当前位置: 首页>>代码示例>>C#>>正文


C# ActionBlock.PropagateCompleted方法代码示例

本文整理汇总了C#中ActionBlock.PropagateCompleted方法的典型用法代码示例。如果您正苦于以下问题:C# ActionBlock.PropagateCompleted方法的具体用法?C# ActionBlock.PropagateCompleted怎么用?C# ActionBlock.PropagateCompleted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ActionBlock的用法示例。


在下文中一共展示了ActionBlock.PropagateCompleted方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetFileLinesEnumeratorBlock

        public static IPropagatorBlock<File, FileLine> GetFileLinesEnumeratorBlock()
        {
            var resultsBlock = new BufferBlock<FileLine>();
            var actionBlock = new ActionBlock<File>(
                async file =>
                {
                    using (var reader = new System.IO.StreamReader(new System.IO.FileStream(
                        file.FullPath,
                        System.IO.FileMode.Open,
                        System.IO.FileAccess.Read,
                        System.IO.FileShare.Read,
                        bufferSize: 4096,
                        useAsync: true)))
                    {
                        string line;
                        var row = 1;
                        while ((line = await reader.ReadLineAsync()) != null)
                        {
                            if (!string.IsNullOrWhiteSpace(line))
                            {
                                resultsBlock.Post(new FileLine(file, row, line));
                            }

                            row++;
                        }
                    }
                },
                new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = Utils.GlobalMaxDegreeOfParallelism });

            actionBlock.PropagateCompleted(resultsBlock);
            return DataflowBlock.Encapsulate(actionBlock, resultsBlock);
        }
开发者ID:eugene-sea,项目名称:FileWordsDataflow,代码行数:32,代码来源:FileLinesEnumerator.cs

示例2: GetLineSplitterBlock

        public static IPropagatorBlock<FileLinesEnumerator.FileLine, FileLineWord> GetLineSplitterBlock()
        {
            var resultsBlock = new BufferBlock<FileLineWord>();
            var actionBlock = new ActionBlock<FileLinesEnumerator.FileLine>(
                l =>
                {
                    int? wordStart = null;
                    var endOfProcesssing = false;
                    for (var col = 1; !endOfProcesssing; ++col)
                    {
                        endOfProcesssing = col > l.Line.Length;
                        var ch = endOfProcesssing ? ' ' : l.Line[col - 1];
                        if (char.IsLetter(ch))
                        {
                            if (!wordStart.HasValue)
                            {
                                wordStart = col;
                            }
                        }
                        else if (wordStart.HasValue)
                        {
                            resultsBlock.Post(new FileLineWord(
                                l.File,
                                l.Line.Substring(wordStart.Value - 1, col - wordStart.Value).ToUpperInvariant(),
                                l.Row,
                                wordStart.Value));
                            wordStart = null;
                        }
                    }
                },
                new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = Utils.GlobalMaxDegreeOfParallelism });

            actionBlock.PropagateCompleted(resultsBlock);
            return DataflowBlock.Encapsulate(actionBlock, resultsBlock);
        }
开发者ID:eugene-sea,项目名称:FileWordsDataflow,代码行数:35,代码来源:LineSplitter.cs

示例3: GetFileWordCreatorBlock

        public static IPropagatorBlock<LineSplitter.FileLineWord, FileWord> GetFileWordCreatorBlock()
        {
            var wordCache = new ConcurrentDictionary<string, Word>();
            var resultsBlock = new BufferBlock<FileWord>();
            var actionBlock = new ActionBlock<LineSplitter.FileLineWord>(
                w =>
                {
                   var word = wordCache.GetOrAdd(w.Word, term => new Word { Term = term });
                    resultsBlock.Post(new FileWord { File = w.File, Word = word, Row = w.Row, Col = w.Col });
                },
                new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = Utils.GlobalMaxDegreeOfParallelism });

            actionBlock.PropagateCompleted(resultsBlock);
            return DataflowBlock.Encapsulate(actionBlock, resultsBlock);
        }
开发者ID:eugene-sea,项目名称:FileWordsDataflow,代码行数:15,代码来源:FileWordCreator.cs

示例4: GetFilesEnumeratorBlock

        public static IPropagatorBlock<EnumerateFolderTask, string> GetFilesEnumeratorBlock()
        {
            var resultsBlock = new BufferBlock<string>();
            var actionBlock = new ActionBlock<EnumerateFolderTask>(
                t =>
                {
                    foreach (
                        var file in Directory.EnumerateFiles(t.Folder, t.SearchPattern, SearchOption.AllDirectories))
                    {
                        resultsBlock.Post(file);
                    }
                },
                new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = Utils.GlobalMaxDegreeOfParallelism });

            actionBlock.PropagateCompleted(resultsBlock);
            return DataflowBlock.Encapsulate(actionBlock, resultsBlock);
        }
开发者ID:eugene-sea,项目名称:FileWordsDataflow,代码行数:17,代码来源:FilesEnumerator.cs


注:本文中的ActionBlock.PropagateCompleted方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。