簡體   English   中英

來自C#中不同進程的類的訪問實例

[英]Access Instance of a Class from a differente Process in C#

我有一個名為“ Core”的項目,該項目聲明了一個接口。 我有一個名為“ Service”的項目,該項目實例化實現該接口的類(它在依賴項上引用了“ Core”項目)。

這兩個項目都是獨立運行的,因為我可以運行“ Core”(這是一個EXE)。 如果我這樣做,我想驗證“ Service”是否正在運行,如果是,則獲取在“ Service”過程中創建的類的實例並調用它的方法。

看起來像這樣(幾乎)。

在“核心”項目中

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
        }
    }
}

在“服務”項目中

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();
        }
    }
}

它應該以某種方式將其從一個進程轉移到另一個進程,但是我對調用該操作的Interop方法並不熟悉。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM