Access Instance of a Class from a differente Process in C#












0















I have a project called "Core" that declares an Interface. And i have a project called "Service" that instantiates a class that implements that interface (it references the "Core" project on it's dependencies).



Both projects run independently, as i can run "Core" (it's an EXE). If i do, i'd like to verify if "Service" is running, and if so, get the instance of a class that is created on the "Service" process and call it's method.



It looks like this (almost).



On "Core" project:



namespace Core
{
public interface IController { void Update(long ID, string Value, string Components); }

public static class Utils
{
public static IController Controller;

internal void Main(string args)
{
//Here, if "Service" is running, then get "Controller" from it
}
}
}


On the "Service" project:



namespace Service
{
internal class ControlMe : Core.IController
{
public void Update(long ID, string Value, string Components)
{
//Do other things
}

internal void Main(string args)
{
Core.Utils.Controller = new ControlMe();
}
}
}


It should marshal somehow from one process to another, but i'm unfamiliar with Interop methods that would call that.










share|improve this question























  • Be sure to change internal class ControlMe to public class ControlMe. I think you'll have issues with it being internal given your use case.

    – ryancdotnet
    Nov 14 '18 at 17:36






  • 1





    Process interop is quite limited, intentionally. You'll have to use the interop mechanisms provided by .NET. Named pipes, sockets, WCF and a few not worth mentioning because they are way too hard to get right. Don't do it is the only good advice.

    – Hans Passant
    Nov 14 '18 at 17:42











  • i may have been too eager to ask; i've been trying to understand this for a while, but i get is something like this: codeproject.com/Articles/14791/…

    – SammuelMiranda
    Nov 14 '18 at 17:59











  • the internal/public should no be an issue since the class would be captured by an interface reference; the idea is not to instantiate a new one, but capture one that's already running through differente appdomains; maybe the MarshalByRef is the way to do it - did not get yet hou to prevent multiple instances, but i'm reading about it

    – SammuelMiranda
    Nov 14 '18 at 18:01











  • i'll leave this idea alone for now

    – SammuelMiranda
    Nov 27 '18 at 10:29
















0















I have a project called "Core" that declares an Interface. And i have a project called "Service" that instantiates a class that implements that interface (it references the "Core" project on it's dependencies).



Both projects run independently, as i can run "Core" (it's an EXE). If i do, i'd like to verify if "Service" is running, and if so, get the instance of a class that is created on the "Service" process and call it's method.



It looks like this (almost).



On "Core" project:



namespace Core
{
public interface IController { void Update(long ID, string Value, string Components); }

public static class Utils
{
public static IController Controller;

internal void Main(string args)
{
//Here, if "Service" is running, then get "Controller" from it
}
}
}


On the "Service" project:



namespace Service
{
internal class ControlMe : Core.IController
{
public void Update(long ID, string Value, string Components)
{
//Do other things
}

internal void Main(string args)
{
Core.Utils.Controller = new ControlMe();
}
}
}


It should marshal somehow from one process to another, but i'm unfamiliar with Interop methods that would call that.










share|improve this question























  • Be sure to change internal class ControlMe to public class ControlMe. I think you'll have issues with it being internal given your use case.

    – ryancdotnet
    Nov 14 '18 at 17:36






  • 1





    Process interop is quite limited, intentionally. You'll have to use the interop mechanisms provided by .NET. Named pipes, sockets, WCF and a few not worth mentioning because they are way too hard to get right. Don't do it is the only good advice.

    – Hans Passant
    Nov 14 '18 at 17:42











  • i may have been too eager to ask; i've been trying to understand this for a while, but i get is something like this: codeproject.com/Articles/14791/…

    – SammuelMiranda
    Nov 14 '18 at 17:59











  • the internal/public should no be an issue since the class would be captured by an interface reference; the idea is not to instantiate a new one, but capture one that's already running through differente appdomains; maybe the MarshalByRef is the way to do it - did not get yet hou to prevent multiple instances, but i'm reading about it

    – SammuelMiranda
    Nov 14 '18 at 18:01











  • i'll leave this idea alone for now

    – SammuelMiranda
    Nov 27 '18 at 10:29














0












0








0








I have a project called "Core" that declares an Interface. And i have a project called "Service" that instantiates a class that implements that interface (it references the "Core" project on it's dependencies).



Both projects run independently, as i can run "Core" (it's an EXE). If i do, i'd like to verify if "Service" is running, and if so, get the instance of a class that is created on the "Service" process and call it's method.



It looks like this (almost).



On "Core" project:



namespace Core
{
public interface IController { void Update(long ID, string Value, string Components); }

public static class Utils
{
public static IController Controller;

internal void Main(string args)
{
//Here, if "Service" is running, then get "Controller" from it
}
}
}


On the "Service" project:



namespace Service
{
internal class ControlMe : Core.IController
{
public void Update(long ID, string Value, string Components)
{
//Do other things
}

internal void Main(string args)
{
Core.Utils.Controller = new ControlMe();
}
}
}


It should marshal somehow from one process to another, but i'm unfamiliar with Interop methods that would call that.










share|improve this question














I have a project called "Core" that declares an Interface. And i have a project called "Service" that instantiates a class that implements that interface (it references the "Core" project on it's dependencies).



Both projects run independently, as i can run "Core" (it's an EXE). If i do, i'd like to verify if "Service" is running, and if so, get the instance of a class that is created on the "Service" process and call it's method.



It looks like this (almost).



On "Core" project:



namespace Core
{
public interface IController { void Update(long ID, string Value, string Components); }

public static class Utils
{
public static IController Controller;

internal void Main(string args)
{
//Here, if "Service" is running, then get "Controller" from it
}
}
}


On the "Service" project:



namespace Service
{
internal class ControlMe : Core.IController
{
public void Update(long ID, string Value, string Components)
{
//Do other things
}

internal void Main(string args)
{
Core.Utils.Controller = new ControlMe();
}
}
}


It should marshal somehow from one process to another, but i'm unfamiliar with Interop methods that would call that.







c# marshalling marshalbyrefobject






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 17:29









SammuelMirandaSammuelMiranda

13115




13115













  • Be sure to change internal class ControlMe to public class ControlMe. I think you'll have issues with it being internal given your use case.

    – ryancdotnet
    Nov 14 '18 at 17:36






  • 1





    Process interop is quite limited, intentionally. You'll have to use the interop mechanisms provided by .NET. Named pipes, sockets, WCF and a few not worth mentioning because they are way too hard to get right. Don't do it is the only good advice.

    – Hans Passant
    Nov 14 '18 at 17:42











  • i may have been too eager to ask; i've been trying to understand this for a while, but i get is something like this: codeproject.com/Articles/14791/…

    – SammuelMiranda
    Nov 14 '18 at 17:59











  • the internal/public should no be an issue since the class would be captured by an interface reference; the idea is not to instantiate a new one, but capture one that's already running through differente appdomains; maybe the MarshalByRef is the way to do it - did not get yet hou to prevent multiple instances, but i'm reading about it

    – SammuelMiranda
    Nov 14 '18 at 18:01











  • i'll leave this idea alone for now

    – SammuelMiranda
    Nov 27 '18 at 10:29



















  • Be sure to change internal class ControlMe to public class ControlMe. I think you'll have issues with it being internal given your use case.

    – ryancdotnet
    Nov 14 '18 at 17:36






  • 1





    Process interop is quite limited, intentionally. You'll have to use the interop mechanisms provided by .NET. Named pipes, sockets, WCF and a few not worth mentioning because they are way too hard to get right. Don't do it is the only good advice.

    – Hans Passant
    Nov 14 '18 at 17:42











  • i may have been too eager to ask; i've been trying to understand this for a while, but i get is something like this: codeproject.com/Articles/14791/…

    – SammuelMiranda
    Nov 14 '18 at 17:59











  • the internal/public should no be an issue since the class would be captured by an interface reference; the idea is not to instantiate a new one, but capture one that's already running through differente appdomains; maybe the MarshalByRef is the way to do it - did not get yet hou to prevent multiple instances, but i'm reading about it

    – SammuelMiranda
    Nov 14 '18 at 18:01











  • i'll leave this idea alone for now

    – SammuelMiranda
    Nov 27 '18 at 10:29

















Be sure to change internal class ControlMe to public class ControlMe. I think you'll have issues with it being internal given your use case.

– ryancdotnet
Nov 14 '18 at 17:36





Be sure to change internal class ControlMe to public class ControlMe. I think you'll have issues with it being internal given your use case.

– ryancdotnet
Nov 14 '18 at 17:36




1




1





Process interop is quite limited, intentionally. You'll have to use the interop mechanisms provided by .NET. Named pipes, sockets, WCF and a few not worth mentioning because they are way too hard to get right. Don't do it is the only good advice.

– Hans Passant
Nov 14 '18 at 17:42





Process interop is quite limited, intentionally. You'll have to use the interop mechanisms provided by .NET. Named pipes, sockets, WCF and a few not worth mentioning because they are way too hard to get right. Don't do it is the only good advice.

– Hans Passant
Nov 14 '18 at 17:42













i may have been too eager to ask; i've been trying to understand this for a while, but i get is something like this: codeproject.com/Articles/14791/…

– SammuelMiranda
Nov 14 '18 at 17:59





i may have been too eager to ask; i've been trying to understand this for a while, but i get is something like this: codeproject.com/Articles/14791/…

– SammuelMiranda
Nov 14 '18 at 17:59













the internal/public should no be an issue since the class would be captured by an interface reference; the idea is not to instantiate a new one, but capture one that's already running through differente appdomains; maybe the MarshalByRef is the way to do it - did not get yet hou to prevent multiple instances, but i'm reading about it

– SammuelMiranda
Nov 14 '18 at 18:01





the internal/public should no be an issue since the class would be captured by an interface reference; the idea is not to instantiate a new one, but capture one that's already running through differente appdomains; maybe the MarshalByRef is the way to do it - did not get yet hou to prevent multiple instances, but i'm reading about it

– SammuelMiranda
Nov 14 '18 at 18:01













i'll leave this idea alone for now

– SammuelMiranda
Nov 27 '18 at 10:29





i'll leave this idea alone for now

– SammuelMiranda
Nov 27 '18 at 10:29












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%2f53305774%2faccess-instance-of-a-class-from-a-differente-process-in-c-sharp%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%2f53305774%2faccess-instance-of-a-class-from-a-differente-process-in-c-sharp%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

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python