|
var geometryGroup = new GeometryGroup();
int numThreads = Environment.ProcessorCount; // 使用处理器数量作为线程池大小
int currentIndex = 0;
int totalBumpDataCount = ThrdResultData.BumpDataList.Count;
var tasks = new List<Task>();
for (int i = 0; i < numThreads; i++)
{
tasks.Add(Task.Run(() =>
{
while (true)
{
int index = Interlocked.Increment(ref currentIndex) - 1;
if (index >= totalBumpDataCount)
{
break; // 所有数据处理完成后退出
}
var bumpData = ThrdResultData.BumpDataList[index];
var point = new System.Windows.Point(bumpData.BumpPosX * scaleX, bumpData.BumpPosY * scaleY);
var radiusX = 25 * scaleX;
var radiusY = 25 * scaleY;
var ellipseGeometry = new EllipseGeometry(point, radiusX, radiusY);
lock (geometryGroup) // 线程安全地将几何形状添加到组中
{
geometryGroup.Children.Add(ellipseGeometry);
}
}
}));
}
Task.WaitAll(tasks.ToArray()); // 等待所有线程完成
// 此时 geometryGroup 包含所有处理后的几何形状
|
|