Pass Objects Across Application Domain Boundaries
The .NET Remoting system makes passing objects across application domain boundaries straightforward. However, to those unfamiliar with .NET Remoting, the results can be very different from those expected. In fact, the most confusing aspect of using multiple application domains stems from the interaction with .NET Remoting and the way objects traverse application domain boundaries.
All types fall into one of three categories: nonremotable, marshal-by-value (MBV), or marshal-by-reference (MBR). Nonremotable types can't cross application domain boundaries and can't be used as arguments or return values in cross-application domain calls.
MBV types are serializable types. When you pass an MBV object across an application domain boundary as an argument or return value, the .NET Remoting system serializes the object's current state, passes it to the destination application domain, and creates a new copy of the object with the same state as the original. This results in a copy of the MBV object existing in both application domains. The two instances are initially identical, but they are independent; changes made to one instance are not reflected in the other instance. Here's an example of a serializable type named Employee that's passed by value across application domain boundaries. public class Employee {
// Member implementations
§
}
MBR types are those classes that derive from System.MarshalByRefObject. When you pass an MBR object across an application domain boundary as an argument or return value, the .NET Remoting system creates a proxy in the destination application domain that represents the remote MBR object. To any class in the destination application domain, the proxy looks and behaves like the remote MBR object that it represents. In reality, when a call is made against the proxy, the .NET Remoting system transparently passes the call and its arguments to the remote application domain and issues the call against the original object. Any results are passed back to the caller via the proxy. Here's a version of the Employee class that's passed by reference instead of by value.
public class Employee : System.MarshalByRefObject {
// Member implementations
§
}
Subscribe to:
Post Comments (Atom)
Archives
-
▼
2008
(167)
-
▼
September
(75)
- Use a Drag-and-Drop Operation
- Validate an Input Control
- Create an Animated System Tray Icon
- Make a Borderless Form Movable
- Immovable Forms Creation
- Making Multilingual Form in C#
- Using Part of a Main Menu for a Context Menu
- How To Link a Context Menu to a Control
- How to Sort a List View by Any Column
- How to Use an Autocomplete Combo Box
- Restrict a Text Box to Numeric Input
- Force a List Box to Scroll
- Save the Size and Location of a Form
- Find All MDI Child Forms
- Track the Visible Forms in an Application
- Process All the Controls on a Form
- Link Data to a Control in C#
- Add a Control Programmatically in C#
- Perform an XSL Transform
- Generate a Class from a Schema
- Create a Schema for a .NET Class
- Use XML Serialization with Custom Objects
- Validate an XML Document Against a Schema
- Read and Write XML Without Loading an Entire Docum...
- Find Elements with an XPath Search
- Get XML Nodes in a Specific XML Namespace
- Find Specific Elements by Name
- Quickly Append Nodes in an XML Document
- Insert Nodes in an XML Document
- Connecting to a Password-Protected Access Database...
- Connecting to a Microsoft Excel Workbook in ADO
- Connecting to an ODBC Data Source in ADO
- Ensure That Only One Instance of an Application Ca...
- Start a New Process
- Terminate a Process
- Create a Thread-Safe Collection Instance
- Synchronize the Execution of Multiple Threads
- How To Know When a Thread Finishes
- Control the Execution of a Thread
- Execute a Method Using a New Thread
- Execute a Method by Signaling a WaitHandle Object
- Execute a Method Using a Timer
- Execute a Method Asynchronously
- Execute a Method Using the Thread Pool
- Inspect the Attributes of a Program Element Using ...
- Create a Custom Attribute
- Instantiate an Object Using Reflection
- Test an Object's Type
- Retrieve Type Information
- Retrieve Type Information
- Unload Assemblies and Application Domains
- Pass Data Between Application Domains
- Instantiate a Type in a Different Application Domain
- Execute an Assembly in a Different Application Domain
- Load an Assembly into the Current Application Domain
- Create a Type That Can't Cross Application Domain ...
- Creating an Application Domain
- Connecting to an ODBC Data Source
- Avoid Loading Unnecessary Assemblies into Applicat...
- Pass Objects Across Application Domain Boundaries
- Store a Serializable Object to a File
- Create a Strongly Typed Collection
- Copy a Collection to an Array
- Sort an Array or an ArrayList
- Add, Subtract, and Compare Dates and Times
- Creating Dates and Times from Strings
- Use Compiled Regular Expressions
- Validate Input Using Regular Expressions in Csharp
- Encode Binary Data as Text in Csharp
- Convert Basic Value Types to Byte Arrays
- Encode a String Using Alternate Character Encoding
- Prevent People from Decompiling Your Code
- Manage the Global Assembly Cache in Csharp
- Create and Trust a Test Software Publisher Certifi...
- Sign an Assembly with an Authenticode Digital Sign...
-
▼
September
(75)
No comments:
Post a Comment