Program.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using Dto;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Configuration;
  5. using System.Linq;
  6. using System.Messaging;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace QueueWriter.Console
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. GatherAndSend();
  16. }
  17. private static void GatherAndSend()
  18. {
  19. System.Console.WriteLine("type some stuff to queue up");
  20. var input = System.Console.ReadLine();
  21. using (var mq = new MessageQueue(ConfigurationManager.AppSettings["OperationMessageQueuePath"]))
  22. {
  23. var qItem = new QueuedWorkItem() { Name = input };
  24. using (var msg = new System.Messaging.Message(qItem))
  25. {
  26. msg.Label = "Queued Item from the console";
  27. msg.Formatter = new XmlMessageFormatter(new Type[] { typeof(QueuedWorkItem) });
  28. mq.Send(msg);
  29. System.Console.WriteLine("Message sent. Message ID is {0}", msg.Id);
  30. }
  31. }
  32. System.Console.WriteLine("write another message to the queue? Y/N");
  33. var decision = System.Console.ReadLine();
  34. if (decision == "y")
  35. { GatherAndSend(); }
  36. }
  37. }
  38. }