本文整理汇总了C#中Thread.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# Thread.ToList方法的具体用法?C# Thread.ToList怎么用?C# Thread.ToList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thread
的用法示例。
在下文中一共展示了Thread.ToList方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AggregationTest
public void AggregationTest()
{
var random = new Random(
int.Parse(Guid.NewGuid().ToString().Replace("-", "").Substring(0, 7), NumberStyles.HexNumber)
);
//параметры теста
var writeThreadCount = 10;// Environment.ProcessorCount + 2;
var readThreadCount = 6;//Environment.ProcessorCount;// * 2;
var itemCount = 100000;
var maxValue = 1000;
//подготовка данных
var correctAccumulator = 0L;
_datas = new Item[writeThreadCount][];
for (var di = 0; di < writeThreadCount; di++)
{
_datas[di] = new Item[itemCount];
for (var ii = 0; ii < itemCount; ii++)
{
var v = random.Next(maxValue) + 1;
_datas[di][ii] = new Item(v);
//Debug.WriteLine("Generated {0}", v);
correctAccumulator += v;
_totalCount++;
}
}
Debug.WriteLine("CorrectAccumulator {0}", correctAccumulator);
var writeThreads = new Thread[writeThreadCount];
for (var ti = 0; ti < writeThreads.Length; ti++)
{
var wt = new Thread(WriteThread);
//wt.Priority = ThreadPriority.AboveNormal;
writeThreads[ti] = wt;
}
var readThreads = new Thread[readThreadCount];
for (var ti = 0; ti < readThreads.Length; ti++)
{
readThreads[ti] = new Thread(ReadThread);
}
_allThreads = writeThreads.ToList();
_allThreads.AddRange(readThreads);
//run the test
for (var ti = 0; ti < writeThreads.Length; ti++)
{
writeThreads[ti].Start(ti);
}
for (var ti = 0; ti < readThreads.Length; ti++)
{
readThreads[ti].Start(ti);
}
_threadWorkEvent.Set();
var before = DateTime.Now;
//все заеблось!
for (var ti = 0; ti < _allThreads.Count; ti++)
{
_allThreads[ti].Join();
}
var after = DateTime.Now;
Item r;
if (_itemWaitProvider.GetItem(TimeSpan.Zero, out r) == OperationResultEnum.Success)
{
Assert.Fail("чота недочитали!");
}
((IDisposable)_itemWaitProvider).Dispose();
Debug.WriteLine("Total count {0}, written count {1}, read count {2}", _totalCount, _writeCount, _readCount);
Debug.WriteLine("Expected {0}, taken {1}", correctAccumulator, _accumulator);
Debug.WriteLine("Time taken {0}", after - before);
if (string.IsNullOrEmpty(_forceAbortReason))
{
Assert.AreEqual(correctAccumulator, _accumulator);
}
else
{
Debug.WriteLine("FORCE ABORT: " + _forceAbortReason);
Assert.Fail();
}
//.........这里部分代码省略.........