home *** CD-ROM | disk | FTP | other *** search
/ ftp.tcs3.com / ftp.tcs3.com.tar / ftp.tcs3.com / DRIVERS / Audio / Office2010 / InfoPath.en-us / InfLR.cab / FL_ImplementTheDisposeFinalizePattern_snip_142729_ENU____.3643236F_FC70_11D3_A536_0090278A1BB8 < prev    next >
Extensible Markup Language  |  2008-09-17  |  2KB  |  71 lines

  1. ∩╗┐<?xml version="1.0" encoding="utf-8"?>
  2. <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  3.   <CodeSnippet Format="1.0.0">
  4.     <Header>
  5.       <Title>Define a Class that Implements IDisposable</Title>
  6.       <Author>Microsoft Corporation</Author>
  7.       <Description>Implements the Dispose Finalize pattern.</Description>
  8.       <Keywords>
  9.         <Keyword>IDisposable</Keyword>
  10.         <Keyword>Finalize</Keyword>
  11.         <Keyword>Dispose</Keyword>
  12.           <Keyword>release</Keyword>
  13.           <Keyword>resource</Keyword>
  14.       </Keywords>
  15.       <Shortcut>IDispose</Shortcut>
  16.     </Header>
  17.     <Snippet>
  18.       <Imports>
  19.         <Import>
  20.           <Namespace>System</Namespace>
  21.         </Import>
  22.         <Import>
  23.           <Namespace>System.ComponentModel</Namespace>
  24.         </Import>
  25.       </Imports>
  26.       <Declarations>
  27.         <Literal>
  28.           <ID>ClassName</ID>
  29.           <Type />
  30.           <ToolTip>Replace with the name of the class you are implementing.</ToolTip>
  31.           <Default>ResourceClass</Default>
  32.         </Literal>
  33.       </Declarations>
  34.       <Code Language="VB" Kind="type decl">
  35.           <![CDATA[Class $ClassName$
  36.     Implements IDisposable
  37.  
  38.     Private disposed As Boolean = False        ' To detect redundant calls
  39.  
  40.     ' IDisposable
  41.     Protected Overridable Sub Dispose(ByVal disposing As Boolean)
  42.         If Not Me.disposed Then
  43.             If disposing Then
  44.                 ' TODO: free unmanaged resources when explicitly called
  45.             End If
  46.  
  47.             ' TODO: free shared unmanaged resources
  48.         End If
  49.         Me.disposed = True
  50.     End Sub
  51.  
  52. #Region " IDisposable Support "
  53.     ' This code added by Visual Basic to correctly implement the disposable pattern.
  54.     Public Sub Dispose() Implements IDisposable.Dispose
  55.         ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
  56.         Dispose(True)
  57.         GC.SuppressFinalize(Me)
  58.     End Sub
  59.  
  60.     Protected Overrides Sub Finalize()
  61.         ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
  62.         Dispose(False)
  63.         MyBase.Finalize()
  64.     End Sub
  65. #End Region
  66.  
  67. End Class]]>
  68.       </Code>
  69.   </Snippet>
  70. </CodeSnippet>
  71. </CodeSnippets>