public void SetOnNewProcessStarted(OnNewProcessStartedDelegate onNewProcessStarted, string value) { this.value = value; OnNewProcessStartedHandler = onNewProcessStarted; if (!isCallBack) { remoteObject = IPCRegistration.RegisterClient(typeof(RemoteObject), CALLBACK_PIPE_NAME, CALLBACK_OBJECT_NAME); remoteObject.isCallBack = true; remoteObject.SetOnNewProcessStarted(onNewProcessStarted, Process.GetCurrentProcess().Id.ToString()); } }
static void Main(string[] args) { const string PIPE_NAME = "testPipeName33"; const string OBJECT_NAME = "test"; const string CALLBACK_PIPE_NAME = "testPipeName34"; const string CALLBACK_OBJECT_NAME = "testclient"; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if ((args.Length == 0 || args[0] == "s")) { try { IPCRegistration.RegisterServer(PIPE_NAME, OBJECT_NAME); } catch (RemotingException) { remoteObject = IPCRegistration.RegisterClient(typeof(RemoteObject), PIPE_NAME, OBJECT_NAME); remoteObject.OnNewProcessStarted("test"); Application.Exit(); return; } MessageBox.Show("Server:" + Process.GetCurrentProcess().Id); Process.Start(Application.ExecutablePath, "c"); Application.Run(new Form1("Server")); } else { IsClient = true; remoteObject = IPCRegistration.RegisterClient(typeof(RemoteObject), PIPE_NAME, OBJECT_NAME); IPCRegistration.RegisterServer(CALLBACK_PIPE_NAME, CALLBACK_OBJECT_NAME); // Here Client will listen on this channel. remoteObject.SetOnNewProcessStarted(OnNewProcessStarted, Process.GetCurrentProcess().Id.ToString()); MessageBox.Show("Client:" + Process.GetCurrentProcess().Id); Application.Run(new Form1("Client")); } }