Cet article a fait l’objet d’une traduction automatique. Pour afficher l’article en anglais, activez la case d’option Anglais. Vous pouvez également afficher le texte anglais dans une fenêtre contextuelle en faisant glisser le pointeur de la souris sur le texte traduit.
Traduction
Anglais

MarshalByRefObject classe

 

Date de publication : novembre 2016

Permet l’accès aux objets au-delà des limites du domaine d’application dans les applications qui prennent en charge l’accès distant.

Espace de noms:   System
Assembly:  mscorlib (dans mscorlib.dll)

System.Object
  System.MarshalByRefObject
    Microsoft.Build.Utilities.AppDomainIsolatedTask
    Microsoft.Build.Utilities.TaskItem
    Microsoft.Build.Utilities.TaskLoggingHelper
    Microsoft.Win32.RegistryKey
    System.AddIn.Pipeline.ContractBase
    System.AppDomain
    System.AppDomainManager
    System.ComponentModel.Component
    System.ContextBoundObject
    System.Data.Common.DataColumnMapping
    System.Data.Common.DataColumnMappingCollection
    System.Data.Common.DataTableMapping
    System.Data.Common.DataTableMappingCollection
    System.Data.Common.DbDataReader
    System.Data.Common.DbParameter
    System.Data.Common.DbParameterCollection
    System.Data.Common.DbTransaction
    System.Diagnostics.TraceListener
    System.DirectoryServices.SearchResultCollection
    System.Drawing.Brush
    System.Drawing.Drawing2D.CustomLineCap
    System.Drawing.Drawing2D.GraphicsContainer
    System.Drawing.Drawing2D.GraphicsPath
    System.Drawing.Drawing2D.GraphicsPathIterator
    System.Drawing.Drawing2D.GraphicsState
    System.Drawing.Drawing2D.Matrix
    System.Drawing.Font
    System.Drawing.FontFamily
    System.Drawing.Graphics
    System.Drawing.Icon
    System.Drawing.Image
    System.Drawing.Pen
    System.Drawing.Region
    System.Drawing.StringFormat
    System.EnterpriseServices.Internal.AssemblyLocator
    System.EnterpriseServices.RegistrationHelper
    System.IO.FileSystemInfo
    System.IO.IsolatedStorage.IsolatedStorage
    System.IO.Stream
    System.IO.TextReader
    System.IO.TextWriter
    System.Messaging.MessageEnumerator
    System.Messaging.MessageQueueEnumerator
    System.Net.WebRequest
    System.Net.WebResponse
    System.Reflection.AssemblyNameProxy
    System.Runtime.InteropServices.StandardOleMarshalObject
    System.Runtime.Remoting.Lifetime.ClientSponsor
    System.Runtime.Remoting.ObjectHandle
    System.Speech.Recognition.SrgsGrammar.SrgsElement
    System.Threading.RegisteredWaitHandle
    System.Threading.Timer
    System.Threading.WaitHandle
    System.Web.Compilation.ClientBuildManager
    System.Web.Compilation.ClientBuildManagerCallback
    System.Web.Hosting.AppDomainProtocolHandler
    System.Web.Hosting.ApplicationManager
    System.Web.Hosting.HostingEnvironment
    System.Web.Hosting.ISAPIRuntime
    System.Web.Hosting.ProcessHost
    System.Web.Hosting.ProcessHostFactoryHelper
    System.Web.Hosting.ProcessProtocolHandler
    System.Web.Hosting.RecycleLimitMonitor
    System.Web.Hosting.RecycleLimitMonitor.RecycleLimitMonitorSingleton
    System.Web.Hosting.VirtualFileBase
    System.Web.Hosting.VirtualPathProvider
    System.Windows.Forms.BaseCollection
    System.Windows.Forms.NativeWindow
    System.Windows.Forms.NumericUpDownAccelerationCollection
    System.Windows.Forms.OwnerDrawPropertyBag
    System.Windows.Forms.TreeNode
    System.Windows.Interop.DocObjHost
    System.Workflow.Runtime.DebugEngine.DebugController

[SerializableAttribute]
[ComVisibleAttribute(true)]
public abstract class MarshalByRefObject

NomDescription
System_CAPS_protmethodMarshalByRefObject()

Initialise une nouvelle instance de la classe MarshalByRefObject.

NomDescription
System_CAPS_pubmethodCreateObjRef(Type)

Crée un objet qui contient toutes les informations requises pour générer un proxy permettant de communiquer avec un objet distant.

System_CAPS_pubmethodEquals(Object)

Détermine si l'objet spécifié est identique à l'objet actuel.(Hérité de Object.)

System_CAPS_protmethodFinalize()

Autorise un objet à tenter de libérer des ressources et d'exécuter d'autres opérations de nettoyage avant qu'il ne soit récupéré par l'opération garbage collection. (Hérité de Object.)

System_CAPS_pubmethodGetHashCode()

Fait office de fonction de hachage par défaut.(Hérité de Object.)

System_CAPS_pubmethodGetLifetimeService()

Récupère l’objet de service de durée de vie en cours qui contrôle la stratégie de durée de vie de cette instance.

System_CAPS_pubmethodGetType()

Obtient le Type de l'instance actuelle.(Hérité de Object.)

System_CAPS_pubmethodInitializeLifetimeService()

Obtient un objet de service de durée de vie pour contrôler la stratégie de durée de vie de cette instance.

System_CAPS_protmethodMemberwiseClone()

Crée une copie superficielle du Object actuel.(Hérité de Object.)

System_CAPS_protmethodMemberwiseClone(Boolean)

Crée une copie superficielle de l’utilisateur actuel MarshalByRefObject objet.

System_CAPS_pubmethodToString()

Retourne une chaîne qui représente l'objet actuel.(Hérité de Object.)

An application domain is a partition in an operating system process where one or more applications reside. Objects in the same application domain communicate directly. Objects in different application domains communicate either by transporting copies of objects across application domain boundaries, or by using a proxy to exchange messages.

MarshalByRefObject is the base class for objects that communicate across application domain boundaries by exchanging messages using a proxy. Objects that do not inherit from MarshalByRefObject are implicitly marshal by value. When a remote application references a marshal by value object, a copy of the object is passed across application domain boundaries.

MarshalByRefObject objects are accessed directly within the boundaries of the local application domain. The first time an application in a remote application domain accesses a MarshalByRefObject, a proxy is passed to the remote application. Subsequent calls on the proxy are marshaled back to the object residing in the local application domain.

Types must inherit from T:System.MarshalByRefObject when the type is used across application domain boundaries, and the state of the object must not be copied because the members of the object are not usable outside the application domain where they were created.

When you derive an object from T:System.MarshalByRefObject for use across application domain boundaries, you should not override any of its members, nor should you call its methods directly. The runtime recognizes that classes derived from T:System.MarshalByRefObject should be marshaled across app domain boundaries.

This section contains two code examples. The first code example shows how to create an instance of a class in another application domain. The second code example shows a simple class that can be used for remoting.

Example 1

The following code example shows the simplest way to execute code in another application domain. The example defines a class named Worker that inherits T:System.MarshalByRefObject, with a method that displays the name of the application domain in which it is executing. The example creates instances of Worker in the default application domain and in a new application domain.

System_CAPS_noteRemarque

The assembly that contains Worker must be loaded into both application domains, but it could load other assemblies that would exist only in the new application domain.

using System;
using System.Reflection;

public class Worker : MarshalByRefObject
{
    public void PrintDomain() 
    { 
        Console.WriteLine("Object is executing in AppDomain \"{0}\"",
            AppDomain.CurrentDomain.FriendlyName); 
    }
}

class Example
{
    public static void Main()
    {
        // Create an ordinary instance in the current AppDomain
        Worker localWorker = new Worker();
        localWorker.PrintDomain();

        // Create a new application domain, create an instance
        // of Worker in the application domain, and execute code
        // there.
        AppDomain ad = AppDomain.CreateDomain("New domain");
        Worker remoteWorker = (Worker) ad.CreateInstanceAndUnwrap(
            typeof(Worker).Assembly.FullName,
            "Worker");
        remoteWorker.PrintDomain();
    }
}

/* This code produces output similar to the following:

Object is executing in AppDomain "source.exe"
Object is executing in AppDomain "New domain"
 */

Example 2

The following example demonstrates a class derived from T:System.MarshalByRefObject that is used later in remoting.

using System;
using System.Runtime.Remoting;
using System.Security.Permissions;

public class SetObjectUriForMarshalTest  {

    class TestClass : MarshalByRefObject {
    }

    [SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.RemotingConfiguration)] 
    public static void Main()  {

        TestClass obj = new TestClass();    

        RemotingServices.SetObjectUriForMarshal(obj, "testUri");
        RemotingServices.Marshal(obj);

        Console.WriteLine(RemotingServices.GetObjectUri(obj));
    }
}

.NET Framework
Disponible depuis 1.1

Tous les membres statiques publics ( Shared en Visual Basic) de ce type sont thread-safe. Les membres d’instance n’ont pas la garantie d’être thread-safe.

Retour au début
Afficher: