0

im trying to use .Net Remoting to get a value of a variable that i use in a thread of an windows service.

TcpChannel tcpChannel = new TcpChannel(9998);
ChannelServices.RegisterChannel(tcpChannel, false);
Type commonInterfaceType = typeof(MyNameSpace.Core.Engine);
RemotingConfiguration.RegisterWellKnownServiceType(commonInterfaceType,
                                                                "CopyFilePercentage",
                                                                WellKnownObjectMode.SingleCall);
myEngine = Engine.EngineInstance;
myEngine.Start();

But it seams that every time that i use the Client to get that value, a new thread is created returning an empty string.

Any idea why is this happening or am I doing something wrong?

Thanks in advance,

Miguel de Sousa

Miguel de Sousa
  • 324
  • 2
  • 15

2 Answers2

1

WellKnownObjectMode.SingleCall creates a new instance of your class for each call. try WellKnownObjectMode.Singleton

EDIT

Maybe you should read about client activated objects. Turn your singleton object to a class factory and return a new instance of a real worker class(ofcourse inheriting from MarshalByRefObject) which will be used by the client.

so your client will be something like this

var worker = client.GetWorkerClass();
worker.GetSomeData();

and you will have one server object per connection (this may not be the correct terminology).

L.B
  • 114,136
  • 19
  • 178
  • 224
0

well i just used a Global Variable Class not really what I wanted but does the job.

/// <summary>
/// Contains global variables for project.
/// </summary>
public static class GlobalVar
{
    /// <summary>
    /// Global variable that is constant.
    /// </summary>
    public const string GlobalString = "Important Text";

    /// <summary>
    /// Static value protected by access routine.
    /// </summary>
    static int _globalValue;

    /// <summary>
    /// Access routine for global variable.
    /// </summary>
    public static int GlobalValue
    {
        get
        {
            return _globalValue;
        }
        set
        {
            _globalValue = value;
        }
    }

    /// <summary>
    /// Global static field.
    /// </summary>
    public static bool GlobalBoolean;
}
Miguel de Sousa
  • 324
  • 2
  • 15