Guest User

npgsql-listen-notify

a guest
Apr 20th, 2012
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Npgsql;
  5.  
  6. namespace client
  7. {
  8. internal class Program
  9. {
  10. private static void Main(string[] args)
  11. {
  12. Console.WriteLine("Type quit to end.");
  13.  
  14. string connection_string;
  15. connection_string = "Server=<servername>;Port=<port>;User Id=<userid>;Password=<pass>;Database=<db>;Pooling=false;SyncNotification=true;";
  16. NpgsqlConnection con = new NpgsqlConnection(connection_string);
  17. try
  18. {
  19. con.Open();
  20.  
  21. NpgsqlCommand cmd = new NpgsqlCommand("listen demoapp;", con);
  22. cmd.ExecuteNonQuery();
  23. con.Notification += new NotificationEventHandler(con_Notification);
  24. Console.WriteLine("Subscribed to Notifications..");
  25. }
  26. catch (Exception e)
  27. {
  28. Console.WriteLine(e.Message);
  29. }
  30.  
  31. Console.WriteLine("Listening on \"demoapp\"..");
  32.  
  33. string keyin = "";
  34. while (keyin.ToLower() != "quit")
  35. {
  36. keyin = Console.ReadLine();
  37. }
  38.  
  39. con.Close();
  40. con.Dispose();
  41. }
  42.  
  43. private static void con_Notification(object sender, NpgsqlNotificationEventArgs e)
  44. {
  45. Console.WriteLine("Notification received..");
  46. Console.WriteLine(e.Condition);
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment