我已阅读此方法的 documentation但它在细节上相当轻松。
Enable concurrent execution of analyzer actions registered by this analyzer.
究竟并发执行了什么?假设我有:
public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.InvocationExpression);
}
如果被分析的代码包含多个InvocationExpressions,每个表达式是否会在自己的线程上并发分析?
However, such an analyzer must ensure that its actions can execute correctly in parallel.
什么是“ Action ”,我如何确保它“正确”执行?我的 AnalyzeNode
方法是 static
,从不可变状态读取,不写入任何共享状态。够了吗?
启用并发执行有什么缺点吗?
还是我完全误解了这一点?
最佳答案
If the code under analysis contains multiple InvocationExpressions, will each expression be concurrently analyzed on its own thread?
他们可能确实如此。显然不能保证它们是,只有这么多线程。
What constitutes an "action"
“操作”是您使用 RegisterSyntaxNodeAction
等方法注册的委托(delegate)。
My
AnalyzeNode
method isstatic
, reads from immutable state, and does not write to any shared state. Is this enough?
是的。
Are there any drawbacks to enabling concurrent execution?
如果您的操作是读取和写入共享状态,则您要么必须同步这些访问,要么不启用并发执行。
关于c# - AnalysisContext.EnableConcurrentExecution() - 它到底做了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52385996/