Partager via


AppDomainSetup.ApplicationName Propriété

Définition

Obtient ou définit le nom de l'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

Valeur de propriété

String

Le nom de l’application.

Implémente

Exemples

L’exemple suivant montre comment définir la ApplicationName propriété lorsque vous créez un domaine d’application.

L’exemple crée un domaine d’application, puis appelle la AppDomain.CreateInstanceAndUnwrap méthode pour charger l’exemple d’assembly dans le nouveau domaine d’application et créer une instance de la Worker classe. La Worker classe hérite MarshalByRefObject, de sorte que l’exemple peut utiliser le proxy retourné pour CreateInstanceAndUnwrap appeler la TestLoad méthode.

La TestLoad méthode charge un assembly que vous spécifiez. Vous devez spécifier un nom d’assembly valide, complet ou commenter la Load(String) méthode. La TestLoad méthode répertorie les assemblys chargés dans le nouveau domaine d’application, montrant que votre assembly spécifié et l’exemple d’assembly sont chargés.

L’exemple utilise l’attribut LoaderOptimizationAttribute pour indiquer au chargeur d’assembly comment l’application partagera du code entre les domaines d’application.

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

S’applique à