none
AppDomain references times out and file locking RRS feed

  • Question

  • Hi, I have an application where I have a main application AppDomain spawning a number of child AppDomains and I have means to either start and execute a certain app domain (which is a long running process) and can stop it. and when I stop it, it should release all the dlls as they may be synchronized and be replaced.

    Code wise I believe I did everything right since if I run this for under 5 - 10 minutes, everything works great, AppDomains are created, everything initializes fine in an AppDomain and runs, if I try to stop it under 5 - 10 min, it releases all the locks on dlls, so that I can replace them.

    I communicate with my AppDomains with MarshalByRef object, which passes only primitive types between main domain and child, so there is no way that my main AppDomain loads dlls from the child.

    The problem is when I run my AppDomain for longer time, it apears that when I try to stop a child AppDomain, it reports as though everything went fine, but the locks on child dlls are not released... when I restart the whole process, locks are released and I can continue. It seems as though there is some sort of timeout on MarshalByRef object reference, and over time it just expires and I lose control over AppDomain.

    Any help is greatly appreciated!

    Wednesday, October 3, 2012 4:34 PM

Answers

  • I think I've figured it out.

    MarshalByRefObject lease was running out, so I override

    public sealed override object InitializeLifetimeService()
    {
    	// Returning null designates an infinite non-expiring lease.
    	// Ensure that RemotingServices.Disconnect() is called when
    	// it's no longer needed otherwise there will be a memory leak.
    	return null;
    }

    This way my object lives forever, BUT will cause a memory leak so when AppDomain needs to die, make sure to call

    RemotingServices.Disconnect(this);

    where this being an instance of that MarshalByRefObject

    • Marked as answer by Rodion Pronin Wednesday, October 3, 2012 5:01 PM
    Wednesday, October 3, 2012 5:01 PM

All replies

  • I think I've figured it out.

    MarshalByRefObject lease was running out, so I override

    public sealed override object InitializeLifetimeService()
    {
    	// Returning null designates an infinite non-expiring lease.
    	// Ensure that RemotingServices.Disconnect() is called when
    	// it's no longer needed otherwise there will be a memory leak.
    	return null;
    }

    This way my object lives forever, BUT will cause a memory leak so when AppDomain needs to die, make sure to call

    RemotingServices.Disconnect(this);

    where this being an instance of that MarshalByRefObject

    • Marked as answer by Rodion Pronin Wednesday, October 3, 2012 5:01 PM
    Wednesday, October 3, 2012 5:01 PM
  • Hi Rodion,

    Congratulations.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, October 4, 2012 7:31 AM
    Moderator