Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Framework / MS / Internal / Utility / SponsorHelper.cs / 1 / 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
- WebPartEditVerb.cs
- PathSegment.cs
- Bold.cs
- RemoteWebConfigurationHost.cs
- GridViewCommandEventArgs.cs
- TableColumn.cs
- ExpressionBuilderContext.cs
- OperationPickerDialog.cs
- Matrix.cs
- XamlToRtfWriter.cs
- AsyncDataRequest.cs
- ReflectPropertyDescriptor.cs
- AutomationPropertyInfo.cs
- DataGridTableCollection.cs
- IndexOutOfRangeException.cs
- DesignerCategoryAttribute.cs
- SiteMapNodeCollection.cs
- CheckBoxField.cs
- LinkedList.cs
- ElapsedEventArgs.cs
- CLRBindingWorker.cs
- MultiplexingDispatchMessageFormatter.cs
- ToolboxComponentsCreatedEventArgs.cs
- WrapPanel.cs
- NodeInfo.cs
- EdmToObjectNamespaceMap.cs
- AxDesigner.cs
- AxisAngleRotation3D.cs
- PaginationProgressEventArgs.cs
- AbstractDataSvcMapFileLoader.cs
- ScriptManager.cs
- ZipPackage.cs
- PlainXmlDeserializer.cs
- MapPathBasedVirtualPathProvider.cs
- TypedCompletedAsyncResult.cs
- ComponentDispatcherThread.cs
- StatusBarPanel.cs
- TableRowCollection.cs
- GroupQuery.cs
- safelinkcollection.cs
- DesignTimeTemplateParser.cs
- BeginEvent.cs
- RSAPKCS1KeyExchangeFormatter.cs
- HttpCacheParams.cs
- WebContext.cs
- BufferCache.cs
- SqlTypeConverter.cs
- ProfileService.cs
- DataGridViewEditingControlShowingEventArgs.cs
- IUnknownConstantAttribute.cs
- ThreadPool.cs
- WebInvokeAttribute.cs
- StringSorter.cs
- XamlPointCollectionSerializer.cs
- DocumentsTrace.cs
- ProcessThread.cs
- StylusPointPropertyInfoDefaults.cs
- StandardCommands.cs
- DataViewSettingCollection.cs
- WebPartConnectionsEventArgs.cs
- MailSettingsSection.cs
- AstTree.cs
- RecordBuilder.cs
- CodeVariableDeclarationStatement.cs
- NaturalLanguageHyphenator.cs
- RenderDataDrawingContext.cs
- MenuScrollingVisibilityConverter.cs
- ValuePatternIdentifiers.cs
- ProxyAttribute.cs
- ColorIndependentAnimationStorage.cs
- ObjectComplexPropertyMapping.cs
- EnumConverter.cs
- CheckableControlBaseAdapter.cs
- URLMembershipCondition.cs
- DocumentPageHost.cs
- AutomationProperty.cs
- ObjectQueryState.cs
- ServiceContractDetailViewControl.cs
- SqlDataSourceStatusEventArgs.cs
- _ContextAwareResult.cs
- RadioButton.cs
- MatrixConverter.cs
- Drawing.cs
- Point3DIndependentAnimationStorage.cs
- PersonalizationState.cs
- ConnectivityStatus.cs
- TreeViewItem.cs
- ImageListUtils.cs
- InstanceDescriptor.cs
- Activator.cs
- log.cs
- _HTTPDateParse.cs
- MultiAsyncResult.cs
- BrowserCapabilitiesFactoryBase.cs
- HttpListenerPrefixCollection.cs
- XsltContext.cs
- UnauthorizedAccessException.cs
- ToolboxDataAttribute.cs
- VirtualizingPanel.cs
- MemoryMappedFileSecurity.cs