delegate.BeginInvoke 的参数是副本还是引用?
哪里有关于 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.
}
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 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.
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该方法获取对象的引用。
对象不会在 .NET 中复制,除非您专门创建一个副本。
The method gets a reference to the object.
Objects aren't copied in .NET, unless you specifically create a copy.