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


C# BlockingCollection.Aggregate方法代码示例

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


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

示例1: DetachedParentChild

        public void DetachedParentChild()
        {
            //Arrange
              var sequence = new BlockingCollection<int>();
              var child1 = new Action(() => { sequence.Add(2); Thread.Sleep(5000); sequence.Add(4); });
              var parent = new Action(() => { sequence.Add(1); Task.Factory.StartNew(child1); Thread.Sleep(2500); sequence.Add(3); });

              //Act
              var parent_task = Task.Factory.StartNew(parent);
              parent_task.Wait();

              //Assert
              Assert.IsTrue(Enumerable.SequenceEqual(new int[] { 1, 2, 3 }, sequence), sequence.Aggregate(new StringBuilder(), (whole, next) => whole.AppendFormat("{0}|", next)).ToString());
              CollectionAssert.AreEqual(new int[] { 1, 2, 3 }, sequence.ToList());
        }
开发者ID:MarcoDorantes,项目名称:spike,代码行数:15,代码来源:TaskSyncsSpec.cs

示例2: ChangeGeoDataForFiles

        public int ChangeGeoDataForFiles(IEnumerable<string> pathToImageFiles,
            string pathToTrack, int timezone, Action actionDuringIteration, out string errors)
        {
            errors = "";
            if (pathToImageFiles.Count() == 0)
                return 0;

            IEnumerable<GeoData> track;
            try
            {
                using (var gpxeReader = new GpxFileReader(pathToTrack))
                {
                    track = gpxeReader.GetData();
                }
            }
            catch (Exception e)
            {
                errors = String.Format(Resources.ErrorREadTrackFileUI, pathToTrack);
                m_Log.Error(String.Format(Resources.ErrorReadTrackFileLog, pathToTrack), e);
                return 0;
            }
            int countChangedFiles = 0;
            BlockingCollection<string> errosInProcces = new BlockingCollection<string>();
            SynchronizationContext ctx = SynchronizationContext.Current;

            Parallel.ForEach(pathToImageFiles, file =>
                {

                    string error;
                    var res =
                         changeExifInformationInFile(file, createDirectoryForOutput(file), out error,
                                (EXIFFileWorker photoExifInfo, out string er) =>
                                {
                                    er = "";
                                    GeoData? geoData =
                                        new GeoDataWorker().GetGeoForPointByTime(photoExifInfo.GetDateTimeTaken().AddHours(-timezone), track);
                                    if (geoData == null)
                                    {
                                        er = String.Format(EXIFPhotoEditor.Properties.Resources.CantFindCoordsForPhotoUI,
                                            file);
                                        m_Log.ErrorFormat(EXIFPhotoEditor.Properties.Resources.CanTFindCoordsForPhotoLog, file);
                                        return false;
                                    }
                                    photoExifInfo.ChangeGeoData(geoData.Value.Latitude,geoData.Value.Longitude, geoData.Value.Altitude);
                                    return true;
                                });
                    if (res)
                        countChangedFiles++;
                    else
                        errosInProcces.Add(error);

                    actionDuringIteration();

                });

            errors = errosInProcces.Aggregate("", (acum, str) => acum + str + "\r\n");
            return countChangedFiles;
        }
开发者ID:TyurinaMariya,项目名称:EXIFPhotoEditor,代码行数:58,代码来源:ChangeDataClass.cs


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