In your class derived from MarshalByRefObject just
add:
//
public override object InitializeLifetimeService()
{
return null; // means infinite time !
}
//
The method will be called by framework automatically.
DanielG
--- Bob Grommes <[EMAIL PROTECTED]> wrote:
>
> Look up the help on leases. Your server object
> probably has a lease that is
> expiring on you. You can set an indefinite lease if
> you require an object
> with an open-ended lifetime. It's been some time
> since I've written that
> sort of code and I don't recall the specifics but
> it's quite simple. I seem
> to recall that the default lease is just a few
> minutes.
>
> --Bob
>
> ----- Original Message -----
> From: "Conspiracy Brother" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, December 03, 2004 10:14 AM
> Subject: [C#.NET] .Net Remoting Troubles
>
>
> >
> > I am working with .Net Remoting. What I am trying
> to do is have a host
> > running on a machine that uses a timer event to
> update a counter value.
> > On a different machine I have a client which calls
> into the host and gets
> > the counter values. Everything works but the
> counter value resets to zero
> > (0) after some time even though the host runs
> continuously. The counter
> > should not reset. Can anyone tell me why this
> happens and point me to any
> > remoting resources for C#? Below is the code:
> >
> >
> > using System;
> > using System.Timers;
> > namespace PCServer
> > {
> > /// <summary>
> > /// Summary description for MyServer.
> > /// </summary>
> > public class MyServer : MarshalByRefObject
> > {
> > private static long counter = 0;
> > public MyServer()
> > {
> > Timer t = new Timer();
> > t.Interval = 1000;
> > t.Enabled = true;
> > t.Elapsed += new
> System.Timers.ElapsedEventHandler(OnTimerEvent);
> > }
> > private void OnTimerEvent(object sender,
> System.Timers.ElapsedEventArgs
> > e)
> > {
> > counter++;
> > }
> > public long GetCounter()
> > {
> > return counter;
> > }
> > }
> > }
> >
>
******************************************************************************************************
> > using System;
> > using System.Runtime.Remoting;
> > using System.Runtime.Remoting.Channels;
> > using System.Runtime.Remoting.Channels.Http;
> > namespace PCHost
> > {
> > /// <summary>
> > /// Summary description for MyHost.
> > /// </summary>
> > public class MyHost
> > {
> > static void Main(string[] args)
> > {
> > HttpChannel myChannel = new HttpChannel(8080);
> > ChannelServices.RegisterChannel(myChannel);
> >
> >
>
RemotingConfiguration.RegisterWellKnownServiceType(typeof(PCServer.MyServer),"MyServer",
> > WellKnownObjectMode.Singleton);
> > Console.ReadLine();
> > }
> > }
> > }
> >
>
******************************************************************************************************
> > using System;
> > using System.Drawing;
> > using System.Collections;
> > using System.ComponentModel;
> > using System.Windows.Forms;
> > using System.Data;
> > using PCServer;
> > using System.Runtime.Remoting;
> > using System.Runtime.Remoting.Channels;
> > using System.Runtime.Remoting.Channels.Http;
> > namespace PCClient
> > {
> > /// <summary>
> > /// Summary description for Form1.
> > /// </summary>
> > public class Form1 : System.Windows.Forms.Form
> > {
> > private System.Windows.Forms.Button button1;
> > /// <summary>
> > /// Required designer variable.
> > /// </summary>
> > private System.ComponentModel.Container
> components = null;
> > public Form1()
> > {
> > //
> > // Required for Windows Form Designer support
> > //
> > InitializeComponent();
> > //
> > // TODO: Add any constructor code after
> InitializeComponent call
> > //
> > HttpChannel c = new HttpChannel();
> > ChannelServices.RegisterChannel(c);
> > }
> > /// <summary>
> > /// Clean up any resources being used.
> > /// </summary>
> > protected override void Dispose( bool disposing )
> > {
> > if( disposing )
> > {
> > if (components != null)
> > {
> > components.Dispose();
> > }
> > }
> > base.Dispose( disposing );
> > }
> > #region Windows Form Designer generated code
> > /// <summary>
> > /// Required method for Designer support - do not
> modify
> > /// the contents of this method with the code
> editor.
> > /// </summary>
> > private void InitializeComponent()
> > {
> > this.button1 = new
> System.Windows.Forms.Button();
> > this.SuspendLayout();
> > //
> > // button1
> > //
> > this.button1.Location = new
> System.Drawing.Point(32, 16);
> > this.button1.Name = "button1";
> > this.button1.Size = new System.Drawing.Size(88,
> 23);
> > this.button1.TabIndex = 0;
> > this.button1.Text = "Counter Value";
> > this.button1.Click += new
> System.EventHandler(this.button1_Click);
> > //
> > // Form1
> > //
> > this.AutoScaleBaseSize = new
> System.Drawing.Size(5, 13);
> > this.ClientSize = new System.Drawing.Size(152,
> 61);
> > this.Controls.Add(this.button1);
> > this.Name = "Form1";
> > this.Text = "PC Test";
> > this.ResumeLayout(false);
> > }
> > #endregion
> > /// <summary>
> > /// The main entry point for the application.
> > /// </summary>
> > [STAThread]
> > static void Main()
> > {
> > Application.Run(new Form1());
> > }
> > private void button1_Click(object sender,
> System.EventArgs e)
> > {
> > MyServer server =
> (MyServer)Activator.GetObject(typeof(MyServer),
> > "http://aMachineOnTheNetwork:8080/MyServer",
> > WellKnownObjectMode.Singleton);
> > long val = server.GetCounter();
> > MessageBox.Show("Counter = " + val, "Report
> Counter Value",
> > MessageBoxButtons.OK);
> > }
>
=== message truncated ===
__________________________________
Do you Yahoo!?
Yahoo! Mail - 250MB free storage. Do more. Manage less.
http://info.mail.yahoo.com/mail_250
| Yahoo! Groups Sponsor | |
|
|
Yahoo! Groups Links
- To visit your group on the web, go to:
http://groups.yahoo.com/group/CSharpNET/
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
