简体   繁体   中英

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.

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:

Since asynchronous notifications are rarely used and processing can be complex, Npgsql only processes notification messages as part of regular (synchronous) query interaction. That is, if an asynchronous notification is sent, Npgsql will only process it and


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.

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

every 5 seconds and this triggers the asynchronous notification in .net.

Any of you know any .net postgre db layer that handles notifications without having this kind of requirement?

Thanks!

Since asynchronous notifications are rarely used and processing can be complex, Npgsql only processes notification messages as part of regular (synchronous) query interaction. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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