I want to communicate between two processes through IPC communication. I made 2 projects 'A' and 'B' using winform.
I would like to do if I enter each number in the textbox of "Process A" and click the Set button to display the additional values of the two numbers entered in the "Process B" text box. For example If I enter 1 and 2 in the "Process A" then press Set button, 3 the additional values of 1 and 2 would be shown in the "Process B".
Here is my code:
[Process A]
private void Form1_Load(object sender, EventArgs e)
{
ServerChannel = new IpcServerChannel("remote");
ChannelServices.RegisterChannel(ServerChannel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject.Object), "Cnt", WellKnownObjectMode.Singleton);
ro = new RemoteObject.Object();
}
private void btnSet_Click(object sender, EventArgs e)
{
try
{
ro.SetAValue(Convert.ToInt32(this.textBox2.Text.ToString()));
ro.SetBValue(Convert.ToInt32(this.textBox3.Text.ToString()));
this.textBox1.AppendText("A : " + ro.GetAValue() + ", B : " + ro.GetBValue() + Environment.NewLine);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
[Process B]
private void Form1_Load(object sender, EventArgs e)
{
try
{
ClientChannel = new IpcClientChannel();
ChannelServices.RegisterChannel(ClientChannel, false);
RemotingConfiguration.RegisterWellKnownClientType(typeof(RemoteObject.Object), "ipc://remote/Cnt");
ro = new RemoteObject.Object();
//timer.Interval = 1000;
//timer.Enabled = true;
//timer.Tick += new EventHandler(timer_Tick);
}
catch (Exception ex)
{
}
}
[RemoteObject]
public class Object : MarshalByRefObject
{
private static int Number1;
private static int Number2;
public int GetAValue()
{
return (Number1);
}
public int GetBValue()
{
return (Number2);
}
public void SetAValue(int cnt)
{
Number1 = cnt;
}
public void SetBValue(int cnt)
{
Number2 = cnt;
}
public int Sum()
{
return (Number1 + Number2);
}
}