[英]npgsql connection wait with ssl
I setup a listener for notification from postresql through npgsql in vb.net. 我设置了一个侦听器,用于通过vb.net中的npgsql从postresql发出通知。 The sub just opens a new ssl connection and starts a new thread with a loop waiting for notification.
子程序只是打开一个新的ssl连接,并使用一个循环等待通知来启动新线程。 Here below is the code
下面是代码
Public Sub StartListening()
If mConnString Is Nothing Then
Main_Form.WriteMessage("Not connected")
End If
Try
connection = New NpgsqlConnection(mConnString) With {
.ProvideClientCertificatesCallback = New ProvideClientCertificatesCallback(AddressOf MyProvideClientCertificates)
}
connection.Open()
If connection.State = ConnectionState.Open Then
Using command = New NpgsqlCommand("listen my_notification", connection)
command.ExecuteNonQuery()
End Using
End If
AddHandler connection.Notification, New NotificationEventHandler(AddressOf OnNotification)
Dim thread As New Thread(
Sub()
While True
connection.Wait()
End While
End Sub
)
thread.Start()
Catch ex As Exception
Main_Form.WriteMessage("Error:" + ex.Message)
End Try
End Sub
Private Sub MyProvideClientCertificates(ByVal clienteCertis As X509CertificateCollection)
Dim cert As X509Certificate2 = New X509Certificate2("mycertificate.pfx")
clienteCertis.Add(cert)
End Sub
Everything was working fine until I introduced SSL connection: it fails on connection.Wait() saying 直到我引入SSL连接,一切都工作正常: 连接失败。Wait()说
Wait() with timeout isn't supported when SSL is used, see https://github.com/npgsql/npgsql/issues/1501
使用SSL时不支持带有超时的Wait(),请参阅https://github.com/npgsql/npgsql/issues/1501
Since actually I don't need a timeout I tried setting timeout=0 and commandtimeout=0 in connection string but error still remains and this is what I see in error stacktrace 由于实际上我不需要超时,因此我尝试在连接字符串中设置timeout = 0和commandtimeout = 0 ,但是错误仍然存在,这就是我在错误stacktrace中看到的内容
in Npgsql.NpgsqlConnector.Wait(Int32 timeout)
在Npgsql.NpgsqlConnector.Wait(Int32超时)
in Npgsql.NpgsqlConnection.Wait(Int32 timeout)
在Npgsql.NpgsqlConnection.Wait(Int32超时)
in Npgsql.NpgsqlConnection.Wait()
在Npgsql.NpgsqlConnection.Wait()中
Could anyone help? 有人可以帮忙吗?
I found a solution. 我找到了解决方案。 I write here just in case some else has the same problem.
我写在这里,以防其他人有同样的问题。
I changed Wait() with WaitAsync() . 我用WaitAsync()更改了Wait () 。
To avoid continuous looping also added Await and declare the sub as Async . 为了避免连续循环,还添加了Await并将子项声明为Async 。
Below is the code 下面是代码
....
Dim thread As New Thread(
Async Sub()
While True
Await connection.WaitAsync()
End While
End Sub
)
thread.Start()
....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.