共享运行的应用程序之间的变量在C# [英] sharing variables between running applications in C#

查看:107
本文介绍了共享运行的应用程序之间的变量在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发的C#两个简单的应用程序,而网络的要求在同一个本地机器上运行。

I am developing in C# two simple applications, running in the same local machine without network requirements.

第一个应用程序初始化一个DLL(1级),并设置一个变量。第二个应用程序刚读它这是以前存储的数据。 。这两个应用程序instanciates相同的Class1

The first application initializes an DLL (Class1) and set a variable. The second application just read it the data which was previously stored. Both applications instanciates the same Class1.

代码:


  • DLL (1级):

  • DLL (Class1):

public class Class1
{

private string variableName;

public string MyProperty
 {
    get { return variableName; }
    set { variableName = value; }
  }

}


  • 应用程序A:

  • Application A:

    class Program
    {
    static void Main(string[] args)
    {
        Class1 class1 = new Class1();
    
        string localReadVariable = Console.ReadLine();
    
        class1.MyProperty = localReadVariable;
    
       }
    }
    


  • 应用程序B:

  • Application B:

    class Program
    {
        static void Main(string[] args)
    {
        ClassLibraryA.Class1 localClass = new ClassLibraryA.Class1();
    
        string z = localClass.MyProperty;
    
        Console.WriteLine(z);
    }
    }
    


  • 我的问题是,我不知道如何阅读从另一个线程的变量。

    My problem is that I do not know how to read a variable from another thread.

    应用程序b必须阅读VARIABLENAME由应用程序b设置

    Application B must read the "variableName" set by application B

    感谢您

    推荐答案

    您需要某种机制的应用程序之间的通信。

    You need some sort of mechanism to communicate between the applications.

    这可以通过注册表,文件的内存映射文件等等...

    This can be through the registry, files, memory mapped files etc...

    如果这两个应用程序都应该做写,你需要同步逻辑添加到您的代码。

    If both applications are expected to do write, you need to add synchronization logic to your code.

    这篇关于共享运行的应用程序之间的变量在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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