本文整理匯總了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