Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Implementing IDisposable in a class
Message
De
13/02/2014 02:18:15
 
 
À
12/02/2014 11:27:02
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01594093
Message ID:
01594217
Vues:
54
This message has been marked as a message which has helped to the initial question of the thread.
>>Don't think you need to oOperationContextScope
>
>This wouldn't work. A Using has to be a direct reference.

Not true. The two approaches::
Namespace ConsoleApplication6
	Class Program
		Private Shared Sub Main(args As String())
			Using mySvc As New SOAPSVC()
				Using mySvc.Something = New OperationContext()
				End Using
			End Using

			Console.WriteLine("====================")
			Dim mySvc2 As New SOAPSVC()
			mySvc2 = Nothing
			GC.Collect()
			Console.WriteLine("Collection complete")
			Console.ReadLine()
		End Sub
	End Class

	Public Class SOAPSVC
		Implements IDisposable
		Private isDisposed As Boolean = False
		' UsedBySOAPSVC instance = new UsedBySOAPSVC();

		Public Sub Dispose() Implements IDisposable.Dispose
			Dispose(True)
			GC.SuppressFinalize(Me)
		End Sub

		Public Property Something() As OperationContext
			Get
				Return m_Something
			End Get
			Set
				m_Something = Value
			End Set
		End Property
		Private m_Something As OperationContext

		Protected Overridable Sub Dispose(disposing As Boolean)
			If Not isDisposed Then
				If disposing Then
					Console.WriteLine("User Disposing SOAPSVC with " & disposing)
					isDisposed = True
				Else
					Console.WriteLine("Finalizer Disposing SOAPSVC with " & disposing)
				End If
			End If
		End Sub

		Protected Overrides Sub Finalize()
			Try
				Console.WriteLine("SOAPSVC Destructor")
				Dispose(False)
			Finally
				MyBase.Finalize()
			End Try
		End Sub
	End Class

	Public Class OperationContext
		Implements IDisposable
		Private isDisposed As Boolean = False
		Public Sub Dispose() Implements IDisposable.Dispose
			Dispose(True)
			GC.SuppressFinalize(Me)
		End Sub

		Public Overridable Sub Dispose(disposing As Boolean)
			If Not isDisposed Then
				If disposing Then
					isDisposed = True
					Console.WriteLine("User Disposing UsedBySOAPSVC")
				Else
					Console.WriteLine("Finalizer Disposing UsedBySOAPSVC")
				End If
			End If
		End Sub

		Protected Overrides Sub Finalize()
			Try
				Console.WriteLine("UsedBySOAPSVC destructor")
				Dispose(False)
			Finally
				MyBase.Finalize()
			End Try
		End Sub
	End Class
End Namespace
>IAC, this no longer exists. This object is now in the Dispose() method.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform