Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / MS / Internal / Utility / SponsorHelper.cs / 1305600 / SponsorHelper.cs
using System;
using System.Diagnostics;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Lifetime;
using System.Security;
using System.Security.Permissions;
namespace MS.Internal.Utility
{
#region SponsorHelper Class
///
/// We either mark the Sponsor as MarshalByRef or make it serializable.
/// If we make it MarshalByRef, then this sponsor which is used to control
/// the lifetime of a MBR object in turn needs to have another sponsor OR
/// the sponsor can mark itself to remain alive for the life of the AppDomain
/// by overriding InitializeLifetimeService and returning null OR the object
/// can be marked as Serializeable instead of MBR in which case it is marshaled
/// by value to the client appdomain and will not have the state of the host
/// appdomain to make renewal decisions. In our case we don't have any state so
/// its easier and better perf-wise to mark it Serializable.
///
[Serializable]
internal class SponsorHelper : ISponsor
{
#region Private Data
private ILease _lease;
private TimeSpan _timespan;
#endregion Private Data
#region Constructor
internal SponsorHelper(ILease lease, TimeSpan timespan)
{
Debug.Assert(lease != null && timespan != null, "Lease and TimeSpan arguments cannot be null");
_lease = lease;
_timespan = timespan;
}
#endregion Constructor
#region ISponsor Interface
TimeSpan ISponsor.Renewal(ILease lease)
{
if (lease == null)
{
throw new ArgumentNullException("lease");
}
return _timespan;
}
#endregion ISponsor Interface
#region Internal Methods
///
/// Critical - asserts permission for RemotingConfiguration
/// TreatAsSafe - The constructor for this object is internal and this function does not take
/// random parameters and hence can’t be used to keep random objects alive or access any other object
/// in the application.
///
[SecurityCritical, SecurityTreatAsSafe]
[SecurityPermissionAttribute(SecurityAction.Assert, RemotingConfiguration = true)]
internal void Register()
{
_lease.Register((ISponsor)this);
}
///
/// Critical - asserts permission for RemotingConfiguration
/// TreatAsSafe - The constructor for this object is internal and this function does not take
/// random parameters and hence can’t be used to keep random objects alive or access any other object
/// in the application.
///
[SecurityCritical, SecurityTreatAsSafe]
[SecurityPermissionAttribute(SecurityAction.Assert, RemotingConfiguration = true)]
internal void Unregister()
{
_lease.Unregister((ISponsor)this);
}
#endregion Internal Methods
}
#endregion SponsorHelper Class
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
using System;
using System.Diagnostics;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Lifetime;
using System.Security;
using System.Security.Permissions;
namespace MS.Internal.Utility
{
#region SponsorHelper Class
///
/// We either mark the Sponsor as MarshalByRef or make it serializable.
/// If we make it MarshalByRef, then this sponsor which is used to control
/// the lifetime of a MBR object in turn needs to have another sponsor OR
/// the sponsor can mark itself to remain alive for the life of the AppDomain
/// by overriding InitializeLifetimeService and returning null OR the object
/// can be marked as Serializeable instead of MBR in which case it is marshaled
/// by value to the client appdomain and will not have the state of the host
/// appdomain to make renewal decisions. In our case we don't have any state so
/// its easier and better perf-wise to mark it Serializable.
///
[Serializable]
internal class SponsorHelper : ISponsor
{
#region Private Data
private ILease _lease;
private TimeSpan _timespan;
#endregion Private Data
#region Constructor
internal SponsorHelper(ILease lease, TimeSpan timespan)
{
Debug.Assert(lease != null && timespan != null, "Lease and TimeSpan arguments cannot be null");
_lease = lease;
_timespan = timespan;
}
#endregion Constructor
#region ISponsor Interface
TimeSpan ISponsor.Renewal(ILease lease)
{
if (lease == null)
{
throw new ArgumentNullException("lease");
}
return _timespan;
}
#endregion ISponsor Interface
#region Internal Methods
///
/// Critical - asserts permission for RemotingConfiguration
/// TreatAsSafe - The constructor for this object is internal and this function does not take
/// random parameters and hence can’t be used to keep random objects alive or access any other object
/// in the application.
///
[SecurityCritical, SecurityTreatAsSafe]
[SecurityPermissionAttribute(SecurityAction.Assert, RemotingConfiguration = true)]
internal void Register()
{
_lease.Register((ISponsor)this);
}
///
/// Critical - asserts permission for RemotingConfiguration
/// TreatAsSafe - The constructor for this object is internal and this function does not take
/// random parameters and hence can’t be used to keep random objects alive or access any other object
/// in the application.
///
[SecurityCritical, SecurityTreatAsSafe]
[SecurityPermissionAttribute(SecurityAction.Assert, RemotingConfiguration = true)]
internal void Unregister()
{
_lease.Unregister((ISponsor)this);
}
#endregion Internal Methods
}
#endregion SponsorHelper Class
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- InputLanguageSource.cs
- LinqToSqlWrapper.cs
- PrintingPermission.cs
- TextPointerBase.cs
- BamlRecordHelper.cs
- AggregateNode.cs
- FilteredReadOnlyMetadataCollection.cs
- GridViewRow.cs
- SessionIDManager.cs
- EditorServiceContext.cs
- HttpHandlerActionCollection.cs
- RemotingServices.cs
- CustomCredentialPolicy.cs
- RecordsAffectedEventArgs.cs
- StorageFunctionMapping.cs
- Schema.cs
- FontInfo.cs
- CodeSubDirectoriesCollection.cs
- SizeConverter.cs
- BitmapFrameEncode.cs
- TextCompositionManager.cs
- safelinkcollection.cs
- AggregationMinMaxHelpers.cs
- PageParserFilter.cs
- InstanceValue.cs
- UriParserTemplates.cs
- PointUtil.cs
- BehaviorEditorPart.cs
- XmlSchemaSimpleContentRestriction.cs
- Models.cs
- DoubleCollectionConverter.cs
- StyleBamlRecordReader.cs
- HwndSourceKeyboardInputSite.cs
- CodeDomExtensionMethods.cs
- MdiWindowListItemConverter.cs
- InProcStateClientManager.cs
- PackageFilter.cs
- TreeViewImageGenerator.cs
- PerfCounters.cs
- SimpleHandlerBuildProvider.cs
- ComMethodElementCollection.cs
- TextBox.cs
- ContentAlignmentEditor.cs
- MaterialCollection.cs
- EmptyQuery.cs
- DesignerVerb.cs
- Win32MouseDevice.cs
- WmpBitmapEncoder.cs
- InvokeGenerator.cs
- WebPartHeaderCloseVerb.cs
- MediaPlayer.cs
- TypeConverter.cs
- DrawingContextWalker.cs
- EndOfStreamException.cs
- SerializableAttribute.cs
- UnsignedPublishLicense.cs
- EventsTab.cs
- WindowsFormsHelpers.cs
- DataServiceException.cs
- AnyAllSearchOperator.cs
- SQLCharsStorage.cs
- Atom10FormatterFactory.cs
- LinqDataSourceUpdateEventArgs.cs
- FillErrorEventArgs.cs
- ReflectionUtil.cs
- ObjectConverter.cs
- SocketException.cs
- DataGridViewRow.cs
- TextSpan.cs
- ClientData.cs
- LinkedResourceCollection.cs
- InvalidEnumArgumentException.cs
- PathGeometry.cs
- ManagementOptions.cs
- AuthenticationService.cs
- ColorTransformHelper.cs
- XmlCharacterData.cs
- Util.cs
- Zone.cs
- FileSystemEventArgs.cs
- PrimaryKeyTypeConverter.cs
- SystemIPGlobalStatistics.cs
- XXXOnTypeBuilderInstantiation.cs
- SmiEventSink.cs
- SelectedDatesCollection.cs
- XmlMemberMapping.cs
- CheckBoxList.cs
- RelationHandler.cs
- SiteMapDataSource.cs
- Switch.cs
- HtmlAnchor.cs
- BypassElementCollection.cs
- PointAnimationUsingPath.cs
- LayoutEditorPart.cs
- PixelFormat.cs
- SkipStoryboardToFill.cs
- diagnosticsswitches.cs
- Win32.cs
- SoapEnvelopeProcessingElement.cs
- MTConfigUtil.cs