gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 05:05:34 26 4
gpt4 key购买 nike

在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

关于vb.net - service.close()与service.abort()-WCF示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1155815/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com