T
Trung
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();
}
}
}
//--------------------------------------------------------------------------
--------
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();
}
}
}
//--------------------------------------------------------------------------
--------