【发布时间】:2017-02-06 16:29:36
【问题描述】:
据我了解,您不应该使用并行处理通过其 API 在 Revit 中执行操作。更多信息可在 http://thebuildingcoder.typepad.com/blog/2014/11/the-revit-api-is-never-ever-thread-safe.html
但是,我目前正在处理获取(并且仅获取)然后检查大量数据以做出一些决定的问题。下面给出了一个使用 TPL 的示例代码,它似乎正在工作:
Parallel.ForEach<Element>(allDocumentElementsNotVisibleInCurrentView,
parallelOptions,
element =>
{
MyDerivedElement iaElement = new MyDerivedElement(uiDocument.Document, element, ElementStatusInView.Found);
// The following condition line does the real heavy lifting and can be a lengthy process, involving data extraction from Revit, such as bounding boxes, geometry and curves
if (iaElement.IsContained(iaView))
lock (result)
result.Add(iaElement);
});
所以我的问题是,鉴于以上似乎在测试中有效,让这个通过并行处理是一个好主意吗?
感谢您的帮助!
【问题讨论】:
-
"如果测试通过,那是因为你测试得不够。"
标签: revit-api