【发布时间】:2011-02-10 18:52:01
【问题描述】:
哪里有关于 BeginInvoke 参数处理的文档?
如果我有一个接受对象作为参数的委托(包装了我的处理函数),该对象是否会被异步调用的处理函数复制或引用?
delegate void MyDelegate(SomeObject obj);
// later on:
// invoke the delegate async'ly:
new MyDelegate(StaticClass.HandlerFunc).BeginInvoke(objInstance, null, null);
// alter the object:
objInstance.SomeProperty = newValue;
// function:
public static void HandlerFunc(SomeObject obj) {
// is it a possible race condition to read SomeProperty:
if(obj.SomeProperty == oldValue) {
// will possibly never enter?
}
// ... etc.
}
【问题讨论】:
标签: .net delegates pass-by-reference