AppDomainSetup.ApplicationName 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置应用程序的名称。
public:
property System::String ^ ApplicationName { System::String ^ get(); void set(System::String ^ value); };
public string ApplicationName { get; set; }
member this.ApplicationName : string with get, set
Public Property ApplicationName As String
属性值
应用程序的名称。
实现
示例
以下示例演示如何在创建新的应用程序域时设置 ApplicationName 属性。
该示例创建一个新的应用程序域,然后调用 AppDomain.CreateInstanceAndUnwrap 方法将示例程序集加载到新的应用程序域中,并创建 类的 Worker
实例。 类 Worker
继承 MarshalByRefObject,因此示例可以使用 返回 CreateInstanceAndUnwrap 的代理来调用 TestLoad
方法。
方法 TestLoad
加载指定的程序集。 必须指定有效的完全限定程序集名称,或注释掉 Load(String) 方法。 方法 TestLoad
列出加载到新应用程序域的程序集,显示已加载指定的程序集和示例程序集。
该示例使用 LoaderOptimizationAttribute 特性告诉程序集加载程序应用程序如何跨应用程序域共享代码。
using namespace System;
using namespace System::Reflection;
using namespace System::Security::Policy;
ref class Worker : MarshalByRefObject
{
public:
void TestLoad()
{
// You must supply a valid fully qualified assembly name here.
Assembly::Load("Text assembly name, Culture, PublicKeyToken, Version");
for each (Assembly^ assem in AppDomain::CurrentDomain->GetAssemblies())
Console::WriteLine(assem->FullName);
}
};
//for evidence Object*
// The following attribute indicates to loader that multiple application
// domains are used in this application.
[LoaderOptimizationAttribute(LoaderOptimization::MultiDomainHost)]
int main()
{
// Create application domain setup information for new application domain.
AppDomainSetup^ domaininfo = gcnew AppDomainSetup;
domaininfo->ApplicationBase = System::Environment::CurrentDirectory;
domaininfo->ApplicationName = "MyMultiDomain Application";
//Create evidence for the new appdomain from evidence of current application domain.
Evidence^ adevidence = AppDomain::CurrentDomain->Evidence;
// Create appdomain.
AppDomain^ newDomain = AppDomain::CreateDomain( "MyMultiDomain", adevidence, domaininfo );
// Load an assembly into the new application domain.
Worker^ w = (Worker^) newDomain->CreateInstanceAndUnwrap(
Worker::typeid->Assembly->GetName()->Name,
"Worker"
);
w->TestLoad();
//Unload the application domain, which also unloads the assembly.
AppDomain::Unload(newDomain);
}
using System;
using System.Reflection;
using System.Security.Policy;
class ADMultiDomain
{
// The following attribute indicates to loader that multiple application
// domains are used in this application.
[LoaderOptimizationAttribute( LoaderOptimization.MultiDomainHost)]
public static void Main()
{
// Create application domain setup information for new application domain.
AppDomainSetup domaininfo = new AppDomainSetup();
domaininfo.ApplicationBase = System.Environment.CurrentDirectory;
domaininfo.ApplicationName = "MyMultiDomain Application";
//Create evidence for the new appdomain from evidence of current application domain.
Evidence adevidence = AppDomain.CurrentDomain.Evidence;
// Create appdomain.
AppDomain newDomain = AppDomain.CreateDomain("MyMultiDomain", adevidence, domaininfo);
// Load an assembly into the new application domain.
Worker w = (Worker) newDomain.CreateInstanceAndUnwrap(
typeof(Worker).Assembly.GetName().Name,
"Worker"
);
w.TestLoad();
//Unload the application domain, which also unloads the assembly.
AppDomain.Unload(newDomain);
}
}
class Worker : MarshalByRefObject
{
internal void TestLoad()
{
// You must supply a valid fully qualified assembly name here.
Assembly.Load("Text assembly name, Culture, PublicKeyToken, Version");
foreach (Assembly assem in AppDomain.CurrentDomain.GetAssemblies())
Console.WriteLine(assem.FullName);
}
}
open System
open System.Reflection
type Worker() =
inherit MarshalByRefObject()
member internal _.TestLoad() =
// You must supply a valid fully qualified assembly name here.
Assembly.Load "Text assembly name, Culture, PublicKeyToken, Version" |> ignore
for assem in AppDomain.CurrentDomain.GetAssemblies() do
printfn $"{assem.FullName}"
// The following attribute indicates to loader that multiple application
// domains are used in this application.
[<LoaderOptimizationAttribute(LoaderOptimization.MultiDomainHost)>]
[<EntryPoint>]
let main _ =
// Create application domain setup information for new application domain.
let domaininfo = AppDomainSetup()
domaininfo.ApplicationBase <- System.Environment.CurrentDirectory
domaininfo.ApplicationName <- "MyMultiDomain Application"
//Create evidence for the new appdomain from evidence of current application domain.
let adevidence = AppDomain.CurrentDomain.Evidence
// Create appdomain.
let newDomain = AppDomain.CreateDomain("MyMultiDomain", adevidence, domaininfo)
// Load an assembly into the new application domain.
let w =
newDomain.CreateInstanceAndUnwrap(typeof<Worker>.Assembly.GetName().Name, "Worker" ) :?> Worker
w.TestLoad()
//Unload the application domain, which also unloads the assembly.
AppDomain.Unload newDomain
0
Imports System.Reflection
Imports System.Security.Policy
'Imports System.Data
'for evidence object
Class ADMultiDomain
' The following attribute indicates to loader that multiple application
' domains are used in this application.
<LoaderOptimizationAttribute(LoaderOptimization.MultiDomainHost)> _
Public Shared Sub Main()
' Create application domain setup information for new application domain.
Dim domaininfo As New AppDomainSetup()
domaininfo.ApplicationBase = System.Environment.CurrentDirectory
domaininfo.ApplicationName = "MyMultiDomain Application"
'Create evidence for the new appdomain from evidence of current application domain.
Dim adevidence As Evidence = AppDomain.CurrentDomain.Evidence
' Create appdomain.
Dim newDomain As AppDomain = AppDomain.CreateDomain("MyMultiDomain", adevidence, domaininfo)
'Load an assembly into the new application domain.
Dim w As Worker = CType( _
newDomain.CreateInstanceAndUnwrap(
GetType(Worker).Assembly().GetName().Name, "Worker"),
Worker)
w.TestLoad()
'Unload the application domain, which also unloads the assembly.
AppDomain.Unload(newDomain)
End Sub
End Class
Class Worker
Inherits MarshalByRefObject
Friend Sub TestLoad()
' You must supply a valid assembly display name here.
[Assembly].Load("Text assembly name, Culture, PublicKeyToken, Version")
For Each assem As [Assembly] In AppDomain.CurrentDomain.GetAssemblies()
Console.WriteLine(assem.FullName)
Next
End Sub
End Class