本文整理汇总了VB.NET中System.Runtime.Remoting.ObjectHandle类的典型用法代码示例。如果您正苦于以下问题:VB.NET ObjectHandle类的具体用法?VB.NET ObjectHandle怎么用?VB.NET ObjectHandle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObjectHandle类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: MyType
' 导入命名空间
Imports System.Runtime.Remoting
Public Class MyType
Inherits MarshalByRefObject
Public Sub New()
Console.Write("Created an instance of MyType in an AppDomain with the ")
Console.WriteLine("hashcode {0}", AppDomain.CurrentDomain.GetHashCode())
Console.WriteLine("")
End Sub
Public Function GetAppDomainHashCode() As Integer
Return AppDomain.CurrentDomain.GetHashCode()
End Function 'GetAppDomainHashCode
End Class
Class Test
Public Shared Sub Main()
Console.WriteLine("The hash code of the default AppDomain is {0}.", AppDomain.CurrentDomain.GetHashCode())
Console.WriteLine("")
' Creates another AppDomain.
Dim domain As AppDomain = AppDomain.CreateDomain("AnotherDomain", Nothing, CType(Nothing, AppDomainSetup))
' Creates an instance of MyType defined in the assembly called ObjectHandleAssembly.
Dim obj As ObjectHandle = domain.CreateInstance("ObjectHandleAssembly", "MyType")
' Unwrapps the proxy to the MyType object created in the other AppDomain.
Dim testObj As MyType = CType(obj.Unwrap(), MyType)
If RemotingServices.IsTransparentProxy(testObj) Then
Console.WriteLine("The unwrapped object is a proxy.")
Else
Console.WriteLine("The unwrapped object is not a proxy!")
End If
Console.WriteLine("")
Console.Write("Calling a method on the object located in an AppDomain with the hash code ")
Console.WriteLine(testObj.GetAppDomainHashCode())
End Sub
End Class