本文整理汇总了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());
}
示例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;
}