If a parameter is a reference to an object, will the asynchronous invocation be passed the reference or a copy of the object (by marshalling)?
A:
Why not code a small sample yourself and see?
(I believe "the reference" is the answer.)
Brian
2010-10-22 05:07:21
+2
A:
If a parameter is a reference to an object (meaning a reference type) then what is passed to the method is a reference. However, this is not the case with a value type passed with the ref keyword. This article has relevant examples (figures 13 & 14): http://msdn.microsoft.com/en-us/magazine/cc301332.aspx
Marshalling pertains to communicating outside of the app domain, so it's not related to asynchronously-called delegates per se.
Eric Mickelsen
2010-10-22 05:14:22
A:
As far as I'm aware, there's no object marshalling that occurs just by calling a delegate asynchronously. Here's some code to show an asynchronous delegate call, passing an object reference.
public class Car
{
public string Model { get; set; }
}
public delegate void TransformHandler(Car car);
public static void Transform(Car car)
{
car.Model = "Holden";
}
static void Main(string[] args)
{
Car car = new Car();
car.Model = "Ford";
new TransformHandler(Transform).BeginInvoke(car, null, null);
Thread.Sleep(100);
Console.WriteLine(car.Model); // Prints "Holden", so it wasn't marshalled
}
Joe Daley
2010-10-22 05:17:24