AppDomainSetup.ApplicationName Propriedade
Definição
Obtém ou define o nome do aplicativo.Gets or sets the name of the application.
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
Valor da propriedade
O nome do aplicativo.The name of the application.
Implementações
Exemplos
O exemplo a seguir mostra como definir a ApplicationName propriedade quando você cria um novo domínio de aplicativo.The following example shows how to set the ApplicationName property when you create a new application domain.
O exemplo cria um novo domínio de aplicativo e, em seguida, chama o AppDomain.CreateInstanceAndUnwrap método para carregar o assembly de exemplo no novo domínio de aplicativo e criar uma instância da Worker classe.The example creates a new application domain, and then calls the AppDomain.CreateInstanceAndUnwrap method to load the example assembly into the new application domain and create an instance of the Worker class. A Worker classe herda MarshalByRefObject , portanto, o exemplo pode usar o proxy retornado pelo CreateInstanceAndUnwrap para chamar o TestLoad método.The Worker class inherits MarshalByRefObject, so the example can use the proxy returned by CreateInstanceAndUnwrap to call the TestLoad method.
O TestLoad método carrega um assembly que você especificar.The TestLoad method loads an assembly that you specify. Você deve especificar um nome de assembly válido e totalmente qualificado ou comentar o Load(String) método.You must either specify a valid, fully qualified assembly name, or comment out the Load(String) method. O TestLoad método lista os assemblies que são carregados no novo domínio de aplicativo, mostrando que o assembly especificado e o assembly de exemplo são carregados.The TestLoad method lists the assemblies that are loaded into the new application domain, showing that your specified assembly and the example assembly are loaded.
O exemplo usa o LoaderOptimizationAttribute atributo para informar ao carregador de assembly como o aplicativo compartilhará o código entre domínios de aplicativo.The example uses the LoaderOptimizationAttribute attribute to tell the assembly loader how the application will share code across application domains.
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);
}
}
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