Posted By: footballism | Mar 27th, 2007 @ 6:42 AM
page 1 of 1
Comments: 3 | Views: 2613
footballism
footballism
I've been avalonized!
    I just encounter a piece of tricky code, and apparently, it doesn't work, but the reason why it's not working is a bit tricky indeed:

using System;

public class Client : MarshalByRefObject
{
public delegate void MessageCallBack();
static void Main()
{
AppDomain ad = AppDomain.CreateDomain("ServerDomain");
Client client = (Client)ad.CreateInstanceAndUnwrap(typeof(Client).Assembly.FullName, "Client");
String msg = "Login";
MessageCallBack callback = new MessageCallBack(delegate { Console.WriteLine(msg);});
client.SendMessage(callback);
}

public void SendMessage(MessageCallBack callback)
{
callback();
}
}

Hopefully this piece of puzzle can make your day:D

Sheva
Mar7in
Mar7in
"The Dream of Infinite Processing Power or the Nightmare of Reality"
Take a look at this blog entry: http://odetocode.com/Blogs/scott/archive/2006/09/11/6546.aspx

The code can be changed to work:

using System;

public class Client : MarshalByRefObject
{
public delegate void MessageCallBack();








static String msg = "Login";
public MessageCallBack Callback = new MessageCallBack(delegate { Console.WriteLine(msg);});



static void Main()
{
AppDomain ad = AppDomain.CreateDomain("ServerDomain");
Client client = (Client)ad.CreateInstanceAndUnwrap(typeof(Client).Assembly.FullName, "Client");
client.SendMessage(client.Callback);
}

public void SendMessage(MessageCallBack callback)
{
callback();
}
}
page 1 of 1
Comments: 3 | Views: 2613