Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Implementing IDisposable in a class
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01594093
Message ID:
01594393
Views:
25
IC ... I think ... :).

My excel wrapper is implemented in the way you describe.


>>You're right. And I checked, that is true for the using construct as well.
>>
>>Michel should try something like
>>
>>
>>Using usingObject = New System.ServiceModel.OperationContextScope(loMyService.InnerChannel)
>>      loSOAPSVC.oOperationContextScope = usingObject
>>      .
>>      .
>>end using
>>
>
>Don't think that's save. usingObject will be disposed when the using block exits and any subsequent use of loSOAPSVC.oOperationContextScope will be unsafe. I'd favour having SOAPSVC implement IDisposable. Something like:
Public Class SOAPSVC
>    Implements IDisposable
>
>    Public Property OperationContext() As OperationContext
>        Get
>            Return m_OperationContext
>        End Get
>        Set(value As OperationContext)
>            m_OperationContext = value
>        End Set
>    End Property
>    Private m_OperationContext As OperationContext
>
>
>    Private isDisposed As Boolean = False
>
>    Public Sub Dispose() Implements IDisposable.Dispose
>        Dispose(True)
>        GC.SuppressFinalize(Me)
>    End Sub
>
>
>    Protected Overridable Sub Dispose(disposing As Boolean)
>        If Not isDisposed Then
>            If disposing Then
>                ' This ensures the contained object is disposed in a timely way
>                Me.OperationContext.Dispose()
>                isDisposed = True
>            End If
>        End If
>    End Sub
>
>    Protected Overrides Sub Finalize()
>        Try
>             Dispose(False)
>        Finally
>            MyBase.Finalize()
>        End Try
>    End Sub
>End Class
then just using:
        Using svc As New SOAPSVC
>            svc.OperationContext = New OperationContext
>        End Using

If things have the tendency to go your way, do not worry. It won't last. Jules Renard.
Previous
Reply
Map
View

Click here to load this message in the networking platform