在不同的应用程序中共享类库中的静态数据 [英] Share static data in class library across different application

查看:64
本文介绍了在不同的应用程序中共享类库中的静态数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



实际上我遇到了一个问题,我需要创建一个类库并在两个或多个客户端应用程序之间共享该库的数据。需要的是所有应用程序都具有类库中最新的数据值。



类库示例(它将在GAC中)

命名空间测试

{



公共课测试

{

static int Count = 0;



public string GetSharingData()

{

Count ++;

返回Count.ToString();

}



}

}



现在我将有两个其他应用程序消耗上述dll。我需要的是当app1调用上面库的方法GetSharingData时,它应该收到1.同样当app2做同样的时候,它应该收到2.

在我的情况下两者都得到1.我如果有人可以帮助我,我会非常感激。我已经google了很多但找不到任何东西。

Hi,
Actually i came across a problem where in I need to create a class library and share the data of this library across two or more client applications. The need is that all the application have the latest value of the data in the class library.

Example of class library( it would be in GAC)
namespace Testing
{

public class Testing
{
static int Count = 0;

public string GetSharingData()
{
Count++;
return Count.ToString();
}

}
}

now i would be having two other application consuming the above dll. what i require is that when app1 calls in the method GetSharingData of above library, it should receive 1. Similarly when app2 does the same, it should receive 2.
In my case both are getting 1. I would really appreciate if someone can help me out with the same. I have googled a lot but couldn't find anything.

推荐答案

静态数据只在同一app域中的对象之间共享。由于您有两个客户端应用程序,因此每个应用程序都会将代码副本加载到自己的应用程序域中,因此每个应用程序只能看到该域中的静态数据。



你'我需要将您的数据存储在应用程序可以访问的某个位置,例如数据库,光盘上的文件,注册表等。
Static data is only "shared" among objects in the same app domain. As you have two client apps they are each loading a copy of your code into their own app domain so each can only see the static data in that domain.

You'll need to store your data somewhere both apps can access it such as a database, a file on disc, the registry etc.


这篇关于在不同的应用程序中共享类库中的静态数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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