跨进程访问静态成员 C# [英] Accessing static members across processes C#

查看:50
本文介绍了跨进程访问静态成员 C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,问题来了.我有一个第三方 c# lib,我正在编写一个关于它的工具.所以我想从另一个应用程序监控一些静态容器,但当然我无法在我的应用程序域中访问它们.一个简单的例子是:

Ok, here is the problem. I have a third party c# lib and im kind of writing a tool about it. So there are a few static Containers that i want to monitor from another application but ofcourse i cant reach them in the domain of my app. A simple example would be :

namespace DefinedInAsembly1
{
     public class Resource
     {
       public static IList<DateTime> DateTimes {get;set;}
     }
}

<小时>

 namespace DefinedInAssembly2
 {
    class RunningProgram
    {
      static void Main(string[] args)
      {
         while(true)
         {
          Resource.DateTimes.Add(DateTime.Now); 
          Thread.Sleep(10000);
         }
      }
    }
 }

<小时>

namespace DefinedInAssembly3
{
 class ToolProgram
 {
    static void Main(string[] args)
    {
         //Accessing Resource.DateTimes with the values inserted from RunningProgram
         //Any ideas?
    }

 }
}

推荐答案

您需要使用任何在主机操作系统上可用的 IPC(进程间通信)技术:

You need to use any of available on host OS IPC (Inter Process Commnuication) tecniques:

因此,必须由某人监听的应用程序应该通过其中一个公开自己,以便另一个想要嗅探或影响它们状态的应用程序可以通过这些渠道与它们通信.

So applications that have to be listened by someone, should expose themselves via one of these, so another application that would like to sniff, or affect the state of them, can communicate with them via these channels.

这篇关于跨进程访问静态成员 C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆