473,326 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How to make a shared class that holds cacthed data?

Hi everybody

I write a class named SharedClass that holds catched data that would be
available for all clients by using static method/member.

This class is registered in the assembly folder. And I write 2 client
applications Client1 and Client2 that use SharedClass. But Client2 cannot
get the value that given to SharedClass by Client1.

How can I make SharedClass' data available for all clients? Source code is
attached.

Thanks

Trung

//-----------------------------
SharedClass.cs ---------------------------------
using System;
namespace SharedClasses
{
public class SharedClass
{
private static int intSharedValue = 0;
public SharedClass(){}
public static int Value
{
get
{
return intSharedValue;
}
set
{
intSharedValue = value;
}
}
}
}
//--------------------------------------------------------------------------
-------
//-----------------------------
Client1.cs ----------------------------------------
using System;
using SharedClasses;
namespace Client1
{
public class Client1
{
public Client1(){}

[STAThread]
static void Main(string[] args)
{
string strInput = "100";
SharedClass.Value = Convert.ToInt32(strInput);
Console.Write(SharedClass.Value);
Console.ReadLine();
}
}
}
//--------------------------------------------------------------------------
--------
//-----------------------------
Client2.cs ---------------------------------------

using System;
using SharedClasses;
namespace Client2
{
class Client2
{

[STAThread]
static void Main(string[] args)
{
Console.WriteLine(SharedClass.Value);
//I expected the output is 100, while Client1 is still running.
But it is not. Why?
//I want to get the value given by Client1. How can I do that?
Console.ReadLine();
}
}
}
//--------------------------------------------------------------------------
--------


Nov 15 '05 #1
1 3443
Hi,

This seems to be the expected behavior as each application owns a separate
application domain containing a single instance of the SharedClass. In other
words, declaring class as "static" means that it will have a single instance
per AppDomain, not per machine.

To overcome this, you will probably have to create a third AppDomain, load
an assembly containing the SharedClass into this domain, and talk to this
class across AppDomain boundaries. This will require some changes to the
SharedClass to support Remoting, though.

In this case, your shared data should live until the third AppDomain is shut
down.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Unit Testing and Integration Environment
http://x-unity.miik.com.ua
Deliver reliable .NET software

"Trung" <tr***@hotmail.com> wrote in message
news:em**************@tk2msftngp13.phx.gbl...
Hi everybody

I write a class named SharedClass that holds catched data that would be
available for all clients by using static method/member.

This class is registered in the assembly folder. And I write 2 client
applications Client1 and Client2 that use SharedClass. But Client2 cannot
get the value that given to SharedClass by Client1.

How can I make SharedClass' data available for all clients? Source code is
attached.

Thanks

Trung

//-----------------------------
SharedClass.cs ---------------------------------
using System;
namespace SharedClasses
{
public class SharedClass
{
private static int intSharedValue = 0;
public SharedClass(){}
public static int Value
{
get
{
return intSharedValue;
}
set
{
intSharedValue = value;
}
}
}
}
//-------------------------------------------------------------------------- -------
//-----------------------------
Client1.cs ----------------------------------------
using System;
using SharedClasses;
namespace Client1
{
public class Client1
{
public Client1(){}

[STAThread]
static void Main(string[] args)
{
string strInput = "100";
SharedClass.Value = Convert.ToInt32(strInput);
Console.Write(SharedClass.Value);
Console.ReadLine();
}
}
}
//-------------------------------------------------------------------------- --------
//-----------------------------
Client2.cs ---------------------------------------

using System;
using SharedClasses;
namespace Client2
{
class Client2
{

[STAThread]
static void Main(string[] args)
{
Console.WriteLine(SharedClass.Value);
//I expected the output is 100, while Client1 is still running. But it is not. Why?
//I want to get the value given by Client1. How can I do that?
Console.ReadLine();
}
}
}
//-------------------------------------------------------------------------- --------


Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Steven T. Hatton | last post by:
This is something I've been looking at because it is central to a currently broken part of the KDevelop new application wizard. I'm not complaining about it being broken, It's a CVS images. ...
0
by: Trung | last post by:
Hi everybody I write a class named SharedClass that holds catched data that would be available for all clients by using static method/member. This class is registered in the assembly folder....
2
by: Trung | last post by:
Hi everybody I write a class named SharedClass that holds catched data that would be available for all clients by using static method/member. This class is registered in the assembly folder....
2
by: tshad | last post by:
I have a program I am trying to compile into a dll and am getting a bunch of: the following errors: error BC30469: Reference to a non-shared member requires an object reference. At first, I...
2
by: John Granade | last post by:
I'm looking for the best way to make a dataset available from multiple Windows forms. The dataset is created from an XML file. I have a main form (frmMain) that loads the dataset and reads the...
8
by: Scott Emick | last post by:
I am using the following to compute distances between two lat/long coordinates for a store locator - (VB .NET 2003) it seems to take a long time to iterate through like 100-150 locations -...
4
by: vze1r2ht | last post by:
I have many types of classes and I'm deciding whether to use a single class or multiple classes for EACH type of class. For an example: User class has 3 classes associated with it: User...
10
by: tshad | last post by:
I have a Dll I created in VS 2000. The namespace is MyFunctions and the Class is CryptoUtil. I have a program that is using the Class but it can't access it directly. I have a class (below)...
3
by: cj2 | last post by:
In the code below I want when this web service is first published for the boolean Running.running to be True. It seems to default to false. How can I make this default to True? Once the web...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.