Click here to Skip to main content
16,018,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

1 solution

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.
 
Share this answer
 
Comments
Manish_nautiyal 21-Aug-15 6:33am    
The above is example to share the static data, going forward we can have a singleton object or a configuration code to share among different instances..
F-ES Sitecore 21-Aug-15 6:38am    
No you can't because .net doesn't work like that. Your code needs to access a shared resource, keeping in mind thread safety issues as both objects might want to update the data store at the same time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900