ActivationContext 类

定义

标识当前应用程序的激活上下文。Identifies the activation context for the current application. 此类不能被继承。This class cannot be inherited.

public ref class ActivationContext sealed : IDisposable, System::Runtime::Serialization::ISerializable
[System.Runtime.InteropServices.ComVisible(false)]
[System.Serializable]
public sealed class ActivationContext : IDisposable, System.Runtime.Serialization.ISerializable
type ActivationContext = class
    interface IDisposable
    interface ISerializable
Public NotInheritable Class ActivationContext
Implements IDisposable, ISerializable
继承
ActivationContext
属性
实现

示例

下面的代码示例演示如何使用ActivationContext对象获取基于清单的应用程序的。 ApplicationIdentityThe following code example demonstrates the use of an ActivationContext object to obtain the ApplicationIdentity for a manifest-based application. 为获得正确的结果, 请将此代码示例作为基于清单的应用程序执行。For correct results, execute this code example as a manifest-based application.

using System;
using System.Collections;
using System.Text;
using System.Security.Policy;
using System.Reflection;
using System.Security;
using System.Security.Permissions;

namespace ActivationContextSample
{
    public class Program : MarshalByRefObject
    {
        [SecurityPermission(SecurityAction.LinkDemand, ControlDomainPolicy=true)]
        public static void Main(string[] args)
        {
            ActivationContext ac = AppDomain.CurrentDomain.ActivationContext;
            ApplicationIdentity ai = ac.Identity;
            Console.WriteLine("Full name = " + ai.FullName);
            Console.WriteLine("Code base = " + ai.CodeBase);

            Console.Read();
        }
        [SecurityPermission(SecurityAction.LinkDemand, ControlDomainPolicy=true)]
        public void Run()
        {
            Main(new string[] { });
            Console.ReadLine();
        }
    }
}
Imports System.Collections
Imports System.Text
Imports System.Security.Policy
Imports System.Reflection
Imports System.Security
Imports System.Security.Permissions

Public Class Program
    Inherits MarshalByRefObject

    <SecurityPermission(SecurityAction.LinkDemand, ControlDomainPolicy:=True)> _
    Public Shared Sub Main(ByVal args() As String) 
        Dim ac As ActivationContext = AppDomain.CurrentDomain.ActivationContext
        Dim ai As ApplicationIdentity = ac.Identity
        Console.WriteLine("Full name = " + ai.FullName)
        Console.WriteLine("Code base = " + ai.CodeBase)
        Console.Read()
    
    End Sub

    <SecurityPermission(SecurityAction.LinkDemand, ControlDomainPolicy:=True)> _
    Public Sub Run() 
        Main(New String() {})
        Console.ReadLine()
    
    End Sub
End Class

注解

ActivationContextApplicationIdentity包含, 并提供对应用程序清单的仅限内部访问。The ActivationContext class contains an ApplicationIdentity and provides internal-only access to the application manifest. 激活上下文在基于清单的激活过程中用于设置域策略并提供基于应用程序的安全模型。The activation context is used during manifest-based activation to set up the domain policy and provide an application-based security model. 有关更多信息,请参见 ApplicationSecurityManager 类。For more information, see the ApplicationSecurityManager class.

重要

此类型实现 IDisposable 接口。This type implements the IDisposable interface. 在使用完类型后,您应直接或间接释放类型。When you have finished using the type, you should dispose of it either directly or indirectly. 若要直接释放类型,请在 try/catch 块中调用其 Dispose 方法。To dispose of the type directly, call its Dispose method in a try/catch block. 若要间接释放类型,请使用 using(在 C# 中)或 Using(在 Visual Basic 中)等语言构造。To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). 有关详细信息,请参阅 IDisposable 接口主题中的“使用实现 IDisposable 的对象”一节。For more information, see the "Using an Object that Implements IDisposable" section in the IDisposable interface topic.

属性

ApplicationManifestBytes

获取当前应用程序的 ClickOnce 应用程序清单。Gets the ClickOnce application manifest for the current application.

DeploymentManifestBytes

获取当前应用程序的 ClickOnce 部署清单。Gets the ClickOnce deployment manifest for the current application.

Form

获取当前应用程序的窗体或存储区上下文。Gets the form, or store context, for the current application.

Identity

获取当前应用程序的应用程序标识。Gets the application identity for the current application.

方法

CreatePartialActivationContext(ApplicationIdentity)

使用指定的应用程序标识初始化 ActivationContext 类的新实例。Initializes a new instance of the ActivationContext class using the specified application identity.

CreatePartialActivationContext(ApplicationIdentity, String[])

使用指定的应用程序标识和清单路径数组来初始化 ActivationContext 类的新实例。Initializes a new instance of the ActivationContext class using the specified application identity and array of manifest paths.

Dispose()

释放由 ActivationContext 使用的所有资源。Releases all resources used by the ActivationContext.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
Finalize()

使 ActivationContext 对象在垃圾回收已收回 ActivationContext 之前尝试释放资源并执行其他清理操作。Enables an ActivationContext object to attempt to free resources and perform other cleanup operations before the ActivationContext is reclaimed by garbage collection.

GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

显式界面实现

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

使用将目标对象序列化所需的数据填充 SerializationInfoPopulates a SerializationInfo with the data needed to serialize the target object.

适用于

另请参阅