2010-04-21 72 views
1

哪裏有關於BeginInvoke參數處理的文檔?delegate.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. 
} 

回答

1

該方法獲取對象的引用。

除非您專門創建副本,否則不會在.NET中複製對象。

相關問題