我有一个从我的应用程序到 Office 插件的 WCF Netnamedpipebinding。我注意到,当办公应用程序忙于做其他事情时,我的应用程序在使用 WCF 方法时会锁定。我添加了我的代码示例。似乎代码停止并使用 channel.close 方法等待。
- 将 channel.close 更改为channel.BeginClose的解决方案是什么?
我需要传递给 BeginClose 方法的状态对象是什么?
Public Function RequestPersonStatus(ByVal id As String, ByVal email As String) Using factory As New ChannelFactory(Of IToOffice)(New NetNamedPipeBinding(), New EndpointAddress("net.pipe://localhost/" + XXXXXX)) Dim OfficeChannel As IToOffice = factory.CreateChannel() Try OfficeChannel.RequestPersonStatus(id:=id, email:=email) Catch ex As Exception Return False Finally CloseChannel(CType(OfficeChannel, ICommunicationObject)) End Try End Using Return True End Function
和 closeChannel
Private Sub CloseChannel(ByVal channel As ICommunicationObject)
Try
If channel.State = CommunicationState.Opened Then
Dim caller As New AsyncCallback(AddressOf callback)
channel.BeginClose(caller, New Object)
' channel.Close()
End If
Catch ex As Exception
Log(LogTypes.AllExceptions, "CloseChannel - Error closing the channel. ", ex.ToString)
Finally
channel.Abort()
End Try
End Sub