I am trying to get a simple server/multi-client program working but have run into a security exception. The server is a console program in C# that hosts a single class. The client is a forms program that has a ListBox to contain the messages, a TextBox to input a new message, and send button. When the client program loads it obtaines a reference to the MBR class hosted by the server. It then runs a method on the class called AddUser with the following signature
The thought was that when a new message was sent to the server by a client, the server would go through the ArrayList of referenced ListBoxes and update each one, thereby updating the ListBoxes on all the clients. This gives an exception though. I tried a simpler case of creating a new method on the served class with the following signature:
I then added string to the client side and set it value to @"Set by Client". If I display the string's value to the console before and after using it as the argument to the ChangeString method, I can see that it does indeed change when being set by ref to the server.
My question is, why is a string different from a ListBox? Is there some security setting I can change to allow this to work? Is there a better way? Thanks in advance.
Kirk
C#:
ArrayList users = new ArrayList();
public void AddUser(ref ListBox newLB)
{
users.Add(newLB);
}
The thought was that when a new message was sent to the server by a client, the server would go through the ArrayList of referenced ListBoxes and update each one, thereby updating the ListBoxes on all the clients. This gives an exception though. I tried a simpler case of creating a new method on the served class with the following signature:
C#:
public void ChangeString(ref string msg)
{
msg = @"Changed by Server";
}
I then added string to the client side and set it value to @"Set by Client". If I display the string's value to the console before and after using it as the argument to the ChangeString method, I can see that it does indeed change when being set by ref to the server.
My question is, why is a string different from a ListBox? Is there some security setting I can change to allow this to work? Is there a better way? Thanks in advance.
Kirk