How to create an ipc communication win-form within a project












0















 public partial class Form1 : Form
{
private Process subProcess;
Counter counter = new Counter();
public Form1(string args)
{
InitializeComponent();

if (args.Length == 0 || args[0].IndexOf("-subMonitor") == -1)
{
IpcServerChannel serverChannel = new IpcServerChannel("serverchannel");

RemotingConfiguration.RegisterWellKnownServiceType(typeof(Counter), "counter", WellKnownObjectMode.Singleton);
Console.WriteLine("This is call number " + counter.Count);
Console.WriteLine("This is call number " + counter.Count);
Console.WriteLine("Listening on " + serverChannel.GetChannelUri());

// MainProcess
subProcess = new Process();

subProcess.StartInfo.FileName = Assembly.GetExecutingAssembly().Location;
subProcess.StartInfo.Arguments = "-subMonitor";
subProcess.StartInfo.UseShellExecute = false;

subProcess.Start();

Button btn = new Button();
btn.Size = new Size(100, 100);
btn.Location = new Point(0, 0);
this.Controls.Add(btn);
btn.BringToFront();

btn.MouseUp += new System.Windows.Forms.MouseEventHandler(btnMouseUp);
}
else
{

Button btn = new Button();
btn.Size = new Size(100, 100);
btn.Location = new Point(0, 0);
this.Controls.Add(btn);
btn.BringToFront();

btn.MouseUp += new System.Windows.Forms.MouseEventHandler(btnMouseUp);
// SubProcess
//Console.WriteLine(args[0]);

IpcClientChannel clientChannel = new IpcClientChannel();
RemotingConfiguration.RegisterWellKnownClientType(typeof(Counter), "ipc://serverchannel/counter");

}

}

private void btnMouseUp(object sender, MouseEventArgs e)
{
MessageBox.Show(counter.Count.ToString());
}
}



public class Counter : MarshalByRefObject
{

private static int count = 0;
public int Count
{
get
{
return (count++);
}
}
}


I want to communicate with same program by ipc.
The same subprocess is opened when the process is executed.



for testing, I made a valuable, Counter that is Singleton Object.
I want to be shared a singleton object called Count.
but It is not working.



I want a result.....



If I click a Main btn button, this result is
2,3,4,5
If I click a Sub btn button, this result is
6,7,8



but this result is....



If I click a Main btn button, this result is
2,3,4,5
If I click a Sub btn button, this result is
0,1,2...



It is not Singleton Object.



What is wrong with it?










share|improve this question























  • paste code of IpcServerChannel

    – Timeless
    Nov 23 '18 at 5:33











  • To use .NET Remoting is a bad idea. It became obsolete years ago, even for desktop apps. Maybe, there still exist some dinosaurs, who knows, how to use it, but it's better to use something else. Since you're writing Windows desktop app, WCF will be good choice (albeit it's rather old too). Type "c# wcf ipc" in brower's search box - there are tons of code samples.

    – Dennis
    Nov 23 '18 at 6:58













  • @Timeless: referencesource.microsoft.com/#System.Runtime.Remoting/channels/…

    – Dennis
    Nov 23 '18 at 7:05
















0















 public partial class Form1 : Form
{
private Process subProcess;
Counter counter = new Counter();
public Form1(string args)
{
InitializeComponent();

if (args.Length == 0 || args[0].IndexOf("-subMonitor") == -1)
{
IpcServerChannel serverChannel = new IpcServerChannel("serverchannel");

RemotingConfiguration.RegisterWellKnownServiceType(typeof(Counter), "counter", WellKnownObjectMode.Singleton);
Console.WriteLine("This is call number " + counter.Count);
Console.WriteLine("This is call number " + counter.Count);
Console.WriteLine("Listening on " + serverChannel.GetChannelUri());

// MainProcess
subProcess = new Process();

subProcess.StartInfo.FileName = Assembly.GetExecutingAssembly().Location;
subProcess.StartInfo.Arguments = "-subMonitor";
subProcess.StartInfo.UseShellExecute = false;

subProcess.Start();

Button btn = new Button();
btn.Size = new Size(100, 100);
btn.Location = new Point(0, 0);
this.Controls.Add(btn);
btn.BringToFront();

btn.MouseUp += new System.Windows.Forms.MouseEventHandler(btnMouseUp);
}
else
{

Button btn = new Button();
btn.Size = new Size(100, 100);
btn.Location = new Point(0, 0);
this.Controls.Add(btn);
btn.BringToFront();

btn.MouseUp += new System.Windows.Forms.MouseEventHandler(btnMouseUp);
// SubProcess
//Console.WriteLine(args[0]);

IpcClientChannel clientChannel = new IpcClientChannel();
RemotingConfiguration.RegisterWellKnownClientType(typeof(Counter), "ipc://serverchannel/counter");

}

}

private void btnMouseUp(object sender, MouseEventArgs e)
{
MessageBox.Show(counter.Count.ToString());
}
}



public class Counter : MarshalByRefObject
{

private static int count = 0;
public int Count
{
get
{
return (count++);
}
}
}


I want to communicate with same program by ipc.
The same subprocess is opened when the process is executed.



for testing, I made a valuable, Counter that is Singleton Object.
I want to be shared a singleton object called Count.
but It is not working.



I want a result.....



If I click a Main btn button, this result is
2,3,4,5
If I click a Sub btn button, this result is
6,7,8



but this result is....



If I click a Main btn button, this result is
2,3,4,5
If I click a Sub btn button, this result is
0,1,2...



It is not Singleton Object.



What is wrong with it?










share|improve this question























  • paste code of IpcServerChannel

    – Timeless
    Nov 23 '18 at 5:33











  • To use .NET Remoting is a bad idea. It became obsolete years ago, even for desktop apps. Maybe, there still exist some dinosaurs, who knows, how to use it, but it's better to use something else. Since you're writing Windows desktop app, WCF will be good choice (albeit it's rather old too). Type "c# wcf ipc" in brower's search box - there are tons of code samples.

    – Dennis
    Nov 23 '18 at 6:58













  • @Timeless: referencesource.microsoft.com/#System.Runtime.Remoting/channels/…

    – Dennis
    Nov 23 '18 at 7:05














0












0








0








 public partial class Form1 : Form
{
private Process subProcess;
Counter counter = new Counter();
public Form1(string args)
{
InitializeComponent();

if (args.Length == 0 || args[0].IndexOf("-subMonitor") == -1)
{
IpcServerChannel serverChannel = new IpcServerChannel("serverchannel");

RemotingConfiguration.RegisterWellKnownServiceType(typeof(Counter), "counter", WellKnownObjectMode.Singleton);
Console.WriteLine("This is call number " + counter.Count);
Console.WriteLine("This is call number " + counter.Count);
Console.WriteLine("Listening on " + serverChannel.GetChannelUri());

// MainProcess
subProcess = new Process();

subProcess.StartInfo.FileName = Assembly.GetExecutingAssembly().Location;
subProcess.StartInfo.Arguments = "-subMonitor";
subProcess.StartInfo.UseShellExecute = false;

subProcess.Start();

Button btn = new Button();
btn.Size = new Size(100, 100);
btn.Location = new Point(0, 0);
this.Controls.Add(btn);
btn.BringToFront();

btn.MouseUp += new System.Windows.Forms.MouseEventHandler(btnMouseUp);
}
else
{

Button btn = new Button();
btn.Size = new Size(100, 100);
btn.Location = new Point(0, 0);
this.Controls.Add(btn);
btn.BringToFront();

btn.MouseUp += new System.Windows.Forms.MouseEventHandler(btnMouseUp);
// SubProcess
//Console.WriteLine(args[0]);

IpcClientChannel clientChannel = new IpcClientChannel();
RemotingConfiguration.RegisterWellKnownClientType(typeof(Counter), "ipc://serverchannel/counter");

}

}

private void btnMouseUp(object sender, MouseEventArgs e)
{
MessageBox.Show(counter.Count.ToString());
}
}



public class Counter : MarshalByRefObject
{

private static int count = 0;
public int Count
{
get
{
return (count++);
}
}
}


I want to communicate with same program by ipc.
The same subprocess is opened when the process is executed.



for testing, I made a valuable, Counter that is Singleton Object.
I want to be shared a singleton object called Count.
but It is not working.



I want a result.....



If I click a Main btn button, this result is
2,3,4,5
If I click a Sub btn button, this result is
6,7,8



but this result is....



If I click a Main btn button, this result is
2,3,4,5
If I click a Sub btn button, this result is
0,1,2...



It is not Singleton Object.



What is wrong with it?










share|improve this question














 public partial class Form1 : Form
{
private Process subProcess;
Counter counter = new Counter();
public Form1(string args)
{
InitializeComponent();

if (args.Length == 0 || args[0].IndexOf("-subMonitor") == -1)
{
IpcServerChannel serverChannel = new IpcServerChannel("serverchannel");

RemotingConfiguration.RegisterWellKnownServiceType(typeof(Counter), "counter", WellKnownObjectMode.Singleton);
Console.WriteLine("This is call number " + counter.Count);
Console.WriteLine("This is call number " + counter.Count);
Console.WriteLine("Listening on " + serverChannel.GetChannelUri());

// MainProcess
subProcess = new Process();

subProcess.StartInfo.FileName = Assembly.GetExecutingAssembly().Location;
subProcess.StartInfo.Arguments = "-subMonitor";
subProcess.StartInfo.UseShellExecute = false;

subProcess.Start();

Button btn = new Button();
btn.Size = new Size(100, 100);
btn.Location = new Point(0, 0);
this.Controls.Add(btn);
btn.BringToFront();

btn.MouseUp += new System.Windows.Forms.MouseEventHandler(btnMouseUp);
}
else
{

Button btn = new Button();
btn.Size = new Size(100, 100);
btn.Location = new Point(0, 0);
this.Controls.Add(btn);
btn.BringToFront();

btn.MouseUp += new System.Windows.Forms.MouseEventHandler(btnMouseUp);
// SubProcess
//Console.WriteLine(args[0]);

IpcClientChannel clientChannel = new IpcClientChannel();
RemotingConfiguration.RegisterWellKnownClientType(typeof(Counter), "ipc://serverchannel/counter");

}

}

private void btnMouseUp(object sender, MouseEventArgs e)
{
MessageBox.Show(counter.Count.ToString());
}
}



public class Counter : MarshalByRefObject
{

private static int count = 0;
public int Count
{
get
{
return (count++);
}
}
}


I want to communicate with same program by ipc.
The same subprocess is opened when the process is executed.



for testing, I made a valuable, Counter that is Singleton Object.
I want to be shared a singleton object called Count.
but It is not working.



I want a result.....



If I click a Main btn button, this result is
2,3,4,5
If I click a Sub btn button, this result is
6,7,8



but this result is....



If I click a Main btn button, this result is
2,3,4,5
If I click a Sub btn button, this result is
0,1,2...



It is not Singleton Object.



What is wrong with it?







c# winforms ipc






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 5:23









123456lllll123456lllll

13




13













  • paste code of IpcServerChannel

    – Timeless
    Nov 23 '18 at 5:33











  • To use .NET Remoting is a bad idea. It became obsolete years ago, even for desktop apps. Maybe, there still exist some dinosaurs, who knows, how to use it, but it's better to use something else. Since you're writing Windows desktop app, WCF will be good choice (albeit it's rather old too). Type "c# wcf ipc" in brower's search box - there are tons of code samples.

    – Dennis
    Nov 23 '18 at 6:58













  • @Timeless: referencesource.microsoft.com/#System.Runtime.Remoting/channels/…

    – Dennis
    Nov 23 '18 at 7:05



















  • paste code of IpcServerChannel

    – Timeless
    Nov 23 '18 at 5:33











  • To use .NET Remoting is a bad idea. It became obsolete years ago, even for desktop apps. Maybe, there still exist some dinosaurs, who knows, how to use it, but it's better to use something else. Since you're writing Windows desktop app, WCF will be good choice (albeit it's rather old too). Type "c# wcf ipc" in brower's search box - there are tons of code samples.

    – Dennis
    Nov 23 '18 at 6:58













  • @Timeless: referencesource.microsoft.com/#System.Runtime.Remoting/channels/…

    – Dennis
    Nov 23 '18 at 7:05

















paste code of IpcServerChannel

– Timeless
Nov 23 '18 at 5:33





paste code of IpcServerChannel

– Timeless
Nov 23 '18 at 5:33













To use .NET Remoting is a bad idea. It became obsolete years ago, even for desktop apps. Maybe, there still exist some dinosaurs, who knows, how to use it, but it's better to use something else. Since you're writing Windows desktop app, WCF will be good choice (albeit it's rather old too). Type "c# wcf ipc" in brower's search box - there are tons of code samples.

– Dennis
Nov 23 '18 at 6:58







To use .NET Remoting is a bad idea. It became obsolete years ago, even for desktop apps. Maybe, there still exist some dinosaurs, who knows, how to use it, but it's better to use something else. Since you're writing Windows desktop app, WCF will be good choice (albeit it's rather old too). Type "c# wcf ipc" in brower's search box - there are tons of code samples.

– Dennis
Nov 23 '18 at 6:58















@Timeless: referencesource.microsoft.com/#System.Runtime.Remoting/channels/…

– Dennis
Nov 23 '18 at 7:05





@Timeless: referencesource.microsoft.com/#System.Runtime.Remoting/channels/…

– Dennis
Nov 23 '18 at 7:05












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441032%2fhow-to-create-an-ipc-communication-win-form-within-a-project%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441032%2fhow-to-create-an-ipc-communication-win-form-within-a-project%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?