本文整理汇总了C#中ConcurrentStack.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentStack.ToList方法的具体用法?C# ConcurrentStack.ToList怎么用?C# ConcurrentStack.ToList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConcurrentStack
的用法示例。
在下文中一共展示了ConcurrentStack.ToList方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetValuesBeforeValue
public static List<int> GetValuesBeforeValue(List<int> values, int stopperValue)
{
ConcurrentStack<int> valuesToReturn = new ConcurrentStack<int>();
Parallel.For(0, values.Count, (index, loopState) =>
{
if (values[index] != stopperValue)
{
valuesToReturn.Push(values[index]);
}
else
{
loopState.Break();
}
});
return valuesToReturn.ToList();
}
示例2: GetNValues
public static List<int> GetNValues(List<int> values, int countToTake)
{
ConcurrentStack<int> valuesToReturn = new ConcurrentStack<int>();
Parallel.For(0, values.Count, (index, loopState) =>
{
if(index < countToTake)
{
valuesToReturn.Push(values[index]);
}
else
{
loopState.Stop();
}
});
return valuesToReturn.ToList();
}
示例3: ShouldRespectMaxDocCountInBatch
public void ShouldRespectMaxDocCountInBatch()
{
using (var store = NewDocumentStore())
{
using (var session = store.OpenSession())
{
for (int i = 0; i < 100; i++)
{
session.Store(new Company());
}
session.SaveChanges();
}
var id = store.Subscriptions.Create(new SubscriptionCriteria());
var subscription = store.Subscriptions.Open(id, new SubscriptionConnectionOptions{ BatchOptions = new SubscriptionBatchOptions { MaxDocCount = 25 }});
var batchSizes = new ConcurrentStack<Reference<int>>();
subscription.BeforeBatch +=
() => batchSizes.Push(new Reference<int>());
subscription.Subscribe(x =>
{
Reference<int> reference;
batchSizes.TryPeek(out reference);
reference.Value++;
});
var result = SpinWait.SpinUntil(() => batchSizes.ToList().Sum(x => x.Value) >= 100, TimeSpan.FromSeconds(60));
Assert.True(result);
Assert.Equal(4, batchSizes.Count);
foreach (var reference in batchSizes)
{
Assert.Equal(25, reference.Value);
}
}
}
示例4: ShouldRespectMaxBatchSize
public void ShouldRespectMaxBatchSize()
{
using (var store = NewDocumentStore())
{
using (var session = store.OpenSession())
{
for (int i = 0; i < 100; i++)
{
session.Store(new Company());
session.Store(new User());
}
session.SaveChanges();
}
var id = store.Subscriptions.Create(new SubscriptionCriteria());
var subscription = store.Subscriptions.Open(id, new SubscriptionConnectionOptions()
{
BatchOptions = new SubscriptionBatchOptions()
{
MaxSize = 16 * 1024
}
});
var batches = new ConcurrentStack<ConcurrentBag<RavenJObject>>();
subscription.BeforeBatch += () => batches.Push(new ConcurrentBag<RavenJObject>());
subscription.Subscribe(x =>
{
ConcurrentBag<RavenJObject> list;
batches.TryPeek(out list);
list.Add(x);
});
var result = SpinWait.SpinUntil(() => batches.ToList().Sum(x => x.Count) >= 200, TimeSpan.FromSeconds(10));
Assert.True(result);
Assert.True(batches.Count > 1);
}
}
示例5: TimeOperation
public static List<TimeSegment> TimeOperation(Action<object, TimeSegment> op, int threads, int batches, object input)
{
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
var times = new ConcurrentStack<TimeSegment>();
for (var i = 0; i < batches; i++)
{
if (threads == 1)
{
var time = new TimeSegment();
op.Invoke(input, time);
times.Push(time);
}
else
{
Parallel.For(0, threads, new Action<int>(delegate(int index)
{
var time = new TimeSegment();
op.Invoke(input, time);
times.Push(time);
}));
}
}
return times.ToList();
}
示例6: Generate_Starting_Solutions
private void Generate_Starting_Solutions(int Number_To_Make)
{
Solution_List_Threading = new ConcurrentStack<Solution>() { };
count = Number_To_Make / NumberOfThreads;
using (e = new CountdownEvent(NumberOfThreads))
{
for (int i = 0; i < NumberOfThreads; i++)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(Generate_Starting_Solutions));
}
e.Wait();
}
Solution_List.AddRange(Solution_List_Threading.ToList());
}
示例7: Parse
private static Tuple<IReadOnlyList<Definitions>, IReadOnlyList<string>> Parse(IReadOnlyList<string> files)
{
var errors = new ConcurrentStack<string>();
var allParts = new Definitions[files.Count];
Parallel.ForEach(files, (file, _, i) => {
try {
allParts[i] = WebIDLParser.Parse(new StreamReader(file, Encoding.UTF8));
}
catch (IOException ex) {
errors.Push("Error reading file " + file + ": " + ex.Message);
}
catch (RecognitionException ex) {
errors.Push(file + "(" + ex.Line + ":" + ex.CharPositionInLine + "): " + ex.GetType().Name + ": " + ex.Message);
}
});
return Tuple.Create<IReadOnlyList<Definitions>, IReadOnlyList<string>>(allParts, errors.ToList());
}
示例8: GetSvnWorkingCopyPaths
private List<string> GetSvnWorkingCopyPaths(string rootPath)
{
if (Directory.Exists(Path.Combine(rootPath, ".svn")))
{
return new List<string>() { rootPath };
}
else
{
ConcurrentStack<string> candidates = new ConcurrentStack<string>();
Directory.EnumerateDirectories(rootPath, "*", SearchOption.TopDirectoryOnly)
.AsParallel()
.ForAll(fld => candidates.PushRange(GetSvnWorkingCopyPaths(fld).ToArray()));
return candidates.ToList();
}
}