473,671 Members | 2,258 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Val ue = Convert.ToInt32 (strInput);
Console.Write(S haredClass.Valu e);
Console.ReadLin e();
}
}
}
//--------------------------------------------------------------------------
--------
//-----------------------------
Client2.cs ---------------------------------------

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

[STAThread]
static void Main(string[] args)
{
Console.WriteLi ne(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.ReadLin e();
}
}
}
//--------------------------------------------------------------------------
--------


Nov 15 '05 #1
1 3467
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******** ******@tk2msftn gp13.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.Val ue = Convert.ToInt32 (strInput);
Console.Write(S haredClass.Valu e);
Console.ReadLin e();
}
}
}
//-------------------------------------------------------------------------- --------
//-----------------------------
Client2.cs ---------------------------------------

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

[STAThread]
static void Main(string[] args)
{
Console.WriteLi ne(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.ReadLin e();
}
}
}
//-------------------------------------------------------------------------- --------


Nov 15 '05 #2

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

Similar topics

12
3293
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. Such things happen. The whole subsystem is going through radical changes. I don't really want to say what I think of the code just yet. That would influence the opinions of others, and I really want to know how other people view these things,...
0
380
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. 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
2
2095
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. 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
2
2953
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 thought it was because I had the sub set as shared, but I get the same error if it take the Shared out. What is causing these errors?
2
6896
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 data but then I have other forms that give the ability to add, modify, and delete rows. This of course changes the dataset and I need that reflected in the main form. At first I was actually passing a reference of the dataset to the "modify" form...
8
3260
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 - about 10-15 seconds...I want to make the code faster. I changed it to be multi-threaded, and it doesn't really make it any faster. The bottleneck seems to be with the math computations. Any ideas like changing my data types or other ideas etc would...
4
2219
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 Class - Holds user properties. Has NO DB related methods (infact has NO methods, only properties lol) etc User Collection class - Holds a collection of user objects
10
2106
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) called CryptoUtil. The functions are Shared functions. I have this Dll in the bin folder of my program. If I don't reference it - it can't seem to find it. If I have:
3
1700
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 service is running and I call it with "start" it works fine as coded. I just don't want to have to call it with start the first time. Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.ComponentModel Imports...
0
8472
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8909
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8596
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8667
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6222
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4221
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4399
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2806
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.