Here is a quick example for using Remoting to talk between 2 application:
1. Create a new project - "RemoteApplication".
1b. Add a refference to System.Runtime.Remoting
2. Double click on the form and add the following code:
private void Form1_Load(object sender, EventArgs e)
{
TcpServerChannel channel = new TcpServerChannel(8085);
ChannelServices.RegisterChannel(channel, false);
ObjRef SiteReference = RemotingServices.Marshal(this, "RemoteForm");
}
3. Change the Form.Text property to "This is the remote form".
4. Run the application (if the windows firewall ask something - click 'allow'\'don't block',etc.).
The form should appear.
5. Create a new project "ApplicationTalker".
6. Double click on the form and add the following code:
private void Form1_Load(object sender, EventArgs e)
{
if (ConnectToRemote())
this.Text = "I got '" + _remoteForm.Text + "' from the other app!";
}
private Form _remoteForm;
privatebool ConnectToRemote()
{
string Url = "tcp://localhost";
int Port = 8085;
string Name = "RemoteForm";
Url +=
":" + Port + "/" + Name;
if (_remoteForm == null)
{
try
{
_remoteForm = (
Form)Activator.GetObject(typeof(Form), Url);
}
catch (Exception ex)
{
System.Windows.Forms.
MessageBox.Show(ex.Message);
return false;
}
}
return true;
}
7. Run the application - you should see the form text changed to "I got - 'This is the remote form' from the other app!".
8. This is it! by using the form, you can search for controls in it, get their properties, etc.