简体   繁体   English

NPGSQL处理要求命令的postgre通知

[英]NPGSQL handling postgre notifications requiring command

I've recently began using SignalR and NPGSQL to handle a notification from postgre db into C# asynchronous code. 我最近开始使用SignalR和NPGSQL处理从postgre db到C#异步代码的通知。

After hours of trying it to work and finally seat down and read what I had to read in the first place, I came to the NpgSql documentation which states: 经过数小时的尝试,终于坐下来阅读了我必须阅读的内容之后,我来到了NpgSql文档,其中指出:

Since asynchronous notifications are rarely used and processing can be complex, Npgsql only processes notification messages as part of regular (synchronous) query interaction. 由于很少使用异步通知,并且处理可能很复杂,因此Npgsql仅将通知消息作为常规(同步)查询交互的一部分进行处理。 That is, if an asynchronous notification is sent, Npgsql will only process it and emit an event to the user the next time a command is sent and processed. 也就是说,如果发送了异步通知,则Npgsql将仅对其进行处理,并在下次发送和处理命令时向用户发出事件。


So, for NpgSql to receive a notification and asynchronously hand it to a custom function in C# it needs to perform another command to actually trigger and receive it. 因此,为使NpgSql接收通知并将其异步传递给C#中的自定义函数,它需要执行另一条命令来实际触发并接收它。

For me, this functionality just breaks everything that at first I was trying to do (receive a notification asynchronously without any other action involved). 对我来说,此功能破坏了我最初尝试做的所有事情(异步接收通知,而无需执行任何其他操作)。

Right now, for ensuring I receive the notification I had to do a timer for a 现在,为了确保我收到通知,我必须为

select 1 选择1

every 5 seconds and this triggers the asynchronous notification in .net. 每5秒触发一次.net中的异步通知。

Any of you know any .net postgre db layer that handles notifications without having this kind of requirement? 你们中谁知道在没有这种要求的情况下处理通知的.net postgre db层?

Thanks! 谢谢!

Since asynchronous notifications are rarely used and processing can be complex, Npgsql only processes notification messages as part of regular (synchronous) query interaction. 由于很少使用异步通知,并且处理可能很复杂,因此Npgsql仅将通知消息作为常规(同步)查询交互的一部分进行处理。 That is, if an asynchronous notification is sent, Npgsql will only process it and emit an event to the user the next time a command is sent and processed. 也就是说,如果发送了异步通知,则Npgsql将仅对其进行处理,并在下次发送和处理命令时向用户发出事件。

Where did you find that? 你是在哪里找到那个东西的。 The Npgsql documentation here shows the proper way to handle notifications in modern versions - you call NpgsqlConnection.Wait() ( WaitAsync() ) repeatedly, and that method will block until a notification is received, dispatching it via the NpgsqlConnection.Notification event. 此处的Npgsql文档显示了处理现代版本中通知的正确方法-反复调用NpgsqlConnection.Wait()WaitAsync() ),该方法将一直阻塞,直到收到通知为止,并通过NpgsqlConnection.Notification事件将其分派。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM