????? ??????? ???? ???? ????? ??????? ?? Visual Basic .NET

?????? ????????? ?????? ?????????
???? ???????: 317336 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

???? ??? ??????? ????? ????? ????? ???? ???? ?????? ???? ?????? ?? Visual Basic .NET. ???? ????? ?? ???? ????? ???? ?????? ?? ?????? ????? ????? ???? ?????? ??? ??? ??????? ?????? ?????? ?? ???????? ?????.

???????

???? ??????? ??????? ??????? ?????? ??? ????? ?????? ???????? ?????? ? ??? ??????? ???? ???????:
  • ???? ??? Microsoft .NET
  • Microsoft Windows 2000 Professional ?? ???? ??????? Microsoft Windows 2000 Server Microsoft Windows XP Professional ?? Microsoft Windows XP Server
????? ??? ??????? ??? ??????? ??? ???????? ???????:
  • ???? ???? ?????? (COM) "?" ??????? ?????
  • ???? ??????
  • ??????? ???? ?????? ?????? ???????

????? ????? ???? ???? ?? Visual Basic .NET

  1. ??? ????? Microsoft Visual Studio .NET.
  2. ?? ??????? ???? ??? ??? ???? ?? ???? ??? ????? ????.
  3. ?? ???? ?????? ????? ???? ? ???? ??? ?????? Visual Basic ??? ????? Project ?? ???? ??? ????? ???? ?????? ??? ?????.
  4. ?? ???? ???? ??? ???? PoolingDemo ??? ?? ???? ??? ?????.
  5. ???? ?? ???? ???? "?????? ??????". ?? ???? ??? ???? ?????? ?????? ???? ?????? ???????? CTRL + ALT + L.
  6. ???? ??????? ??????? ?????? ???? ??? ???? COM ???? ??????:
    1. ?? "?????? ??????" ???? ??? ?????? ?????? ??? ????? ??? ?? ???? ??? ????? ????.
    2. ??? ????? ??????? .NET ? ???? ??? System.EnterpriseServices ?? ????? ???????? ???????? ?? ???? ??? ?????. ???? ???? System.EnterpriseServices ?? ????? ???????? ???????.
    3. ???? ??? ?????. ???? ???? System.EnterpriseServices ??? ?????? ??????? ?? ????? ???? ??????.

????? Poolable ??? ??? Poolable ??? ???????

  1. ???? ??? ?????? ?????? ??? PoolingDemo ?? "?????? ??????" ? ??? ??? ????? ?? ???? ??? ????? ???? ????.
  2. ?? ???? ?????? ????? ???? ???? ? ???? ??? ??? ??? ????? ?? ???? ??? ???. ??? ????? ????????? Class1.vb ??? ????? ??? ???? ?? poolable ? ??? poolable.
  3. ?????? ??? ???? ????? ?????? ?????? ?? ?????? ???????? ???????? ??????? ??? ???? Class1.vb:
    Imports System.EnterpriseServices
    					
  4. ??????? ????? Class1 ????????? ???????? ???????? ???????:
    Public Class Poolable
        Sub New()
            Threading.Thread.Sleep(500)
        End Sub
        Public Sub DoSomething()
            ' Add method contents here.
        End Sub
    End Class
    						
    ????? ??????? ????? ??? ????????? ???????? ???? ????? ????? ?????.
  5. ??? ?? ?????? ??? ????? ServicedComponent ????? ??? ???? "????? ????????" ??? ???????. ?? ?????? ????????? ???????? ??????? ??? ????? ???:
    Inherits ServicedComponent
    					
  6. ???? ??? ????? poolable ???? ??????? ???????:
    1. ?????? ????? ObjectPoolingAttribute ???? ??? ?????? ????? ??? ??? ???? ????? ????? ?? ??? ???????. ?? ?????? ????????? ???????? ??????? ???? ????? ??? ?????? ??? ObjectPoolingAttribute ??? ?????:
      <ObjectPooling(MinPoolSize:=0, MaxPoolSize:=1), JustInTimeActivation(True)>  _  
      							
      ??????: ????? ??? ????? ????? JustInTimeActivation ????? ?????, ?? ????? ??? ??????? ??? ????? ?? ???? ???????. ???? ????? ?????? ????? ?????? ????? ????? ?????? ???? ????? ?? ???? ?????? ??? ????? ?????? ?????? ??????.
    2. ??????? ServicedComponentCanBePooled ?????? ??? ???? ???????. ?????? ??????? CanBePooled ???? ??????? ?????? True ?? ?????? ???????? ???????? ???????:
      Protected Overrides Function CanBePooled() As Boolean
              Return True
          End Function
      						
  7. ?? ?????? ????????? ???????? ??????? ??? ????? ??? poolable:
    Public Class NonPoolable
        Inherits ServicedComponent
        Sub New()
            ' Simulate an expensive operation.
            Threading.Thread.Sleep(500)
        End Sub
        Public Sub DoSomething()
            ' Add method contents here.
        End Sub
    End Class
    					

????? Module1.vb ????? ?????? ?????? ?? ??? ??????

  1. ?? ?????? "???? ????????? ????????" ? ???? ??? ????? ??????? Module1.vb.
  2. ?? ???? ????? ????? ????? ?????? ????????? ??????? ?????? EnterpriseServices ?????? ??????? ??? ????? DisposeObject:
    Imports System.EnterpriseServices
    						
    ??????? DisposeOjbect ?????? ???????? ??? ???? ?????? ???? ???? ??? ????? ???????.
  3. ????? ??????? ??????? ?????? ??????:
    Sub Main()
            Dim StartTime As DateTime = DateTime.Now
            Dim i As Int32
    
            Const Iterations As Int16 = 50
            For i = 1 To Iterations
                Dim D As New NonPoolable()
    
                D.DoSomething()
                ServicedComponent.DisposeObject(D)
            Next
    
            Dim EndTime As DateTime = DateTime.Now
            Dim Elapsed As TimeSpan = EndTime.Subtract(StartTime)
            Dim OperationsPerSecond = Iterations / Elapsed.TotalSeconds
    
            Console.WriteLine("Object Creations / Second = " & OperationsPerSecond)
            System.Console.ReadLine()
    End Sub
    						
    ????????? ???????? ??? ????? ???? ????? ???? ?? NonPoolable ?? ??? Poolable ????? ?? ????? 50 ????? ??. ????????? ???????? ??????? ????? ? ??????? ??????? ?????? ?? ???? ??? ???????? ???? ?? ??????? ?? ??????? ??? ???? ??????.

????? ??? ???? ???????

??? ?? ???? ??? ???? ?? ????? ????? ?????? ??? ???????. ?? ????? ??????? ????? + COM ???? ??? ???? ????? ??? ???????.

?????? ??? ???????? ??? ??????? ?????? ?????? "????? ?????" (Sn.exe) ??????? ?? ?????? ??? ?????? ???? .NET Framework ????? ?????? ??????? (SDK). ?????? ???? ???? ??? ??????? ??????? ?????? ?????? Sn.exe:
-k sn drive letter \ DirectoryToPlaceKey \ .snk KeyName
  1. ???? ???? ????? Visual Studio .NET ???? ??? ???? ? ???? ??? ??????? ? ???? ??? Microsoft Visual Studio .NET ? ??? ??? ????? .NET Visual Studio ? ?? ???? ??? ???? ??????? .NET Visual Studio.
  2. ?? ???? ???????? ???? ????? ??????:
    -k sn drive letter: \ \poolkey.snk Project Root Folder
  3. ???? ??????? ENTER ?????? ??? ????????. ???? ???? ??????? ??????? ?? ???? ???????:
    ????? ??? ??? ????????...
  4. ???? ??? ??????? ?? ??????? ??????? ???? ????? ??????? ??? AssemblyInfo.vb ?? "?????? ??????". ???? ???????? ????? Visual Studio .NET ???? ??????? ?? ??? ????? ??? ????? ?????? ?????. ?? ?????? ????????? ???????? ??????? ??? ??? ??????? ?? ???? ???????:
    <Assembly: AssemblyKeyFile("..\..\poolkey.snk")>
    					

????? ??? ????

Class1.vb

Imports System.EnterpriseServices

<ObjectPooling(MinPoolSize:=0, MaxPoolSize:=1), JustInTimeActivation(True)>  _
Public Class Poolable
    Inherits ServicedComponent
    Sub New()
        ' Simulate an expensive operation.
        Threading.Thread.Sleep(500)
    End Sub

    Public Sub DoSomething()
        ' Add method contents here.
    End Sub

    Protected Overrides Function CanBePooled() As Boolean
        Return True
    End Function
End Class

Public Class NonPoolable
    Inherits ServicedComponent
    Sub New()
        ' Simulate an expensive operation.
        Threading.Thread.Sleep(500)
    End Sub

    Public Sub DoSomething()
        ' Add method contents here.
    End Sub
End Class
				

Module1.vb

Imports System.EnterpriseServices

Module Module1

    Sub Main()
        Dim StartTime As DateTime = DateTime.Now
        Dim i As Int32

        Const Iterations As Int16 = 50
        For i = 1 To Iterations
            'Dim D As New Poolable()
            Dim D As New NonPoolable()

            D.DoSomething()
            ' To return the object to the object pool, use DisposeObject.
            ' This allows the object to be reused from the pool. If you do not call
            ' DisposeObject, the garbage collector does not collect this object, 
            ' and the object is not reused from the object pool.
            ServicedComponent.DisposeObject(D)
        Next

        Dim EndTime As DateTime = DateTime.Now
        Dim Elapsed As TimeSpan = EndTime.Subtract(StartTime)
        Dim OperationsPerSecond = Iterations / Elapsed.TotalSeconds

        Console.WriteLine("Object Creations / Second = " & OperationsPerSecond)
        ' Pause until the user presses ENTER.
        System.Console.ReadLine()
    End Sub

End Module
				

AssemblyInfo.vb

Imports System.Reflection
Imports System.Runtime.InteropServices

' The following set of attributes control general information about an assembly. 
' Change these attribute values to modify the information that is associated with an assembly.

' Review the values of the assembly attributes.

<Assembly: AssemblyTitle("")> 
<Assembly: AssemblyDescription("")> 
<Assembly: AssemblyCompany("")> 
<Assembly: AssemblyProduct("")> 
<Assembly: AssemblyCopyright("")> 
<Assembly: AssemblyTrademark("")> 
<Assembly: CLSCompliant(True)> 
<Assembly: AssemblyKeyFile("..\..\poolkey.snk")> 

'The following GUID is for the ID of the TypeLib if you expose this project to COM.
<Assembly: Guid("30324ED6-329C-4B12-BDA2-8E817F1E2079")> 

' Version information for an assembly consists of the following four values:
'
'      Major Version
'      Minor Version 
'      Build Number
'      Revision
'
' You can specify all of these values, or you can use the asterisk (*) for
' the Build Number and the Revision values.

<Assembly: AssemblyVersion("1.0.*")>
				

???? ?? ???? ?? ???

  1. ???? ??????? F5 ?????? ??????? ?? ??? ???????. ???? ?? ???? ??? ?????? ?????? ????? NonPoolable.
  2. ????? ????? 25 ?????. ???? ???? ??????? ???????:
    ???? ??????? / ?????? = 1.73542243764044
    ??????: ?? ????? ????? ??????? ?????? ????? ?? ???????.
  3. ???? ????? "???????" ?????? ??????? ???? "?" ?????? ??? Visual Studio .NET.
  4. ????? Module1.vb ????? ?????? ????? Poolable. ????? ????? ????? ?? ??????? ??????? Sub ??? ???:
    Dim D As New Poolable()
    					
  5. ???? F5 ?????? ??????? ??? ????.
  6. ????? ??? ????. ????? ??? ???? ??? ??????? (?? ??????):
    ???? ??????? / ?????? = 29.1977213631085
    ???? ??????? ???? ?? ?????? ??? ??????? ???? ?????.
  7. ???? ????? "???????" ?????? ??????? ???? "?" ?????? ??? Visual Studio .NET.

??????? ??????? ????????

?? ???? ?????? CanBePooled. ??? ???? ??? ?????? ?? ????? ??????.

?????

?????? ??? ???? ?? ????????? ??? ????? ????? ?????? COM + ????? ?????? ???????? ????? ??????? ??? ??????? ????? ?????? ??? ???? ???? ???? ???????? ?????? ????? ???????? ???? ?????? ? ???? ??? ???? Microsoft ?????? ??? ?????:
COM + ?????: ????? ??????? ??????? ??????? .NET Enterprise ????? ????? ??????? ???????
http://msdn.microsoft.com/en-us/library/bb985615.aspx

???????

???? ???????: 317336 - ????? ??? ??????: 27/????? ??????/1425 - ??????: 4.4
????? ???
  • Microsoft .NET Framework Class Libraries 1.0
  • Microsoft Enterprise Services (included with the .NET Framework) 1.0
  • Microsoft Visual Basic .NET 2002 Standard Edition
????? ??????: 
kbmt kbhowtomaster KB317336 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????317336

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com