开发者

Arguments to delegate.BeginInvoke are copies or references?

Where is there documentation on the treatment of arguments to BeginInvoke?

If I have a delegate (which wraps my handler function) that accepts an object as a parameter, does that object get copied or referenced by the asynchronously-called handler function?

delegate void MyDelegate(SomeObject obj);

// later o开发者_Python百科n:
// 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.
}


The method gets a reference to the object.

Objects aren't copied in .NET, unless you specifically create a copy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜