Programmer's Highway

C# Tips and simple code

I'm very sorry for machine translation in English.

C# IPC Problem that is automatically disconnected

RemotingException: Requested Service not found.

If you are running a default configuration interprocess communication, will be disconnected automatically if there is no remote connection a certain period of time.
And, Exception below is thrown when you connect from the client.

Requested Service not found

To avoid this problem, we disable the lifetime of the instance by returning a null to override MarshalByRefObject InitializeLifetimeService of the remote object class. http://msdn.microsoft.com/library/en-us/system.marshalbyrefobject.initializelifetimeservice(v=vs.100).aspx

using System;
namespace IpcSample
{
    public class IpcRemoteObject : MarshalByRefObject
    {
        public int Counter { getset; }
     
        /// <summary>
        /// To avoid disconnected automatically
        /// </summary>
        public override object InitializeLifetimeService()
        {
            return null;
        }
    }
}
Visual Studio 2010 .NET Framework 4