Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我用 ILGenerator 编写 DynamicMethod 并且我输出的代码是线程安全的,那么生成的委托是否是线程安全的?
我担心的是IL在方法第一次运行时被编译。如果这是真的,如果其他线程在编译时尝试运行委托会发生什么?
它与标准委托没有任何区别。它们都以MSIL的形式出现在某个地方,JIT会在需要时编译它们。
一旦您以委托形式获得它,它就是您可以调用的代码体。这就是你真正需要知道的。您正在运行的 .NET 的实现(Rotor、Mono、Microsoft 之一)应该使您免于考虑这一点,否则它是实现中的一个错误。