vb.net – service.close()与service.abort() – WCF示例

前端之家收集整理的这篇文章主要介绍了vb.net – service.close()与service.abort() – WCF示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在其中一个WCF教程中,我看到了以下示例代码
Dim service as ...(a WCF service )

try

   ..

   service.close()

catch ex as Exception()
  ... 

   service.abort()

end try

这是确保即使在错误条件下也能释放资源(即连接)的正确方法吗?

我对这个模型好运:
Dim service As New MyService()
Dim closed As Boolean = False
Try
    service.Open()
    If Not service.State = ServiceModel.CommunicationState.Opened Then
        ''Handle a not-opened state here
    End If
    service.MyMethod()
    service.Close()
    closed = true
Catch ex As Exception
    ''Handle errors here
Finally
    If Not closed Then
        service.Abort()
    End If
End Try
service = Nothing
原文链接:https://www.f2er.com/vb/255877.html

猜你在找的VB相关文章