I have a .net WinForms application that loads plugins (dlls) into their own AppDomains, each dll gets its own AppDomain using domain.CreateInstanceAndUnwrap(). All i want is, that these objects remain connected forever (till the application stops).
The InitialLeaseTime is 5 minutes, but i can't find a way to change that. ..
I tried overriding InitializeLifetimeService() of the remote object:
Public Overrides Function InitializeLifetimeService() As Object
Return Nothing
End Function
Here I get a Typeload-Exception, saying that this would break the inheritance rules. Adding
<SecurityPermissionAttribute(SecurityAction.Demand, Flags:=SecurityPermissionFlag.Infrastructure)>
<SecuritySafeCritical>
doesn't change anything.
Then:
Dim tmpObj As Object = domain.CreateInstanceAndUnwrap(type.AssemblyName, type.TypeName)
Dim tmpRemote As tmpRemoteType = CType(tmpObj, tmpRemoteType)
Dim lifetimeService As Object = Runtime.Remoting.RemotingServices.GetLifetimeService(tmpRemote)
Dim lease As ILease = TryCast(lifetimeService, ILease)
If (lease IsNot Nothing) Then
lease.Register(_sponsor)
End If
Doesn't do it neither, because somehow the Renewal() method of the sponsor (not shown here) is never called.
Calling
lease.Renew(TimeSpan.FromMinutes(300))
directly changes the CurrentLeaseTime but not the InitialLeaseTime of the lease.
Finally i tried calling the shared (static) property LeaseTime, which actually led to a change of CurrentLeaseTime at the beginning of the Lease, but again NOT the InitialLeaseTime, which seems to end after 5 minutes and my remote object being gc'ed:
LifetimeServices.RenewOnCallTime = System.TimeSpan.FromMinutes(300)
Any help is appreciated, Thx!