Advertisement
Guest User

Untitled

a guest
Jan 12th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. public delegate void EventHandler();
  2. class someClass
  3. {
  4. WrapperForm dlg = null;
  5. StreamReader reader ;
  6. System.Timers.Timer timer;
  7. static NamedPipeServerStream server;
  8. public void CallToChildThread(Object stateInfo)
  9. {
  10. AutoResetEvent autoEvent = (AutoResetEvent)stateInfo;
  11. if (server.IsConnected)
  12. {
  13. string tempString = reader.ReadLine();
  14. server.Flush();
  15. //Fire event
  16. _show.Invoke();
  17. }
  18. else
  19. {
  20. server.WaitForConnectionAsync();
  21. }
  22. autoEvent.Set();
  23. }
  24. public someClass()
  25. {
  26. public static event EventHandler _show;
  27. server = new NamedPipeServerStream("TagCnfConnection", PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
  28. server.WaitForConnectionAsync();
  29. initializeDialog(); // Initialize the dialog. Standard new
  30. reader = new StreamReader(server);
  31. var autoEvent = new AutoResetEvent(false);
  32. var stateTimer = new System.Threading.Timer(CallToChildThread,
  33. autoEvent, 1000, 250);
  34. _show += new EventHandler(eventCheck);
  35. }
  36. void eventCheck()
  37. {
  38. //If some condition
  39. dlg.ShowDialog();
  40. }
  41. }
  42.  
  43. if (args == null)
  44. {
  45. PwLogger.WriteFeedback(Severity.PRI_CRITICAL, "No Aargument");
  46. return; // return if not
  47. }
  48. else //Do the work
  49. {
  50. StreamReader reader = null;
  51. StreamWriter writer = null;
  52. try
  53. {
  54.  
  55. NamedPipeClientStream client = new NamedPipeClientStream("TagCnfConnection");
  56. client.Connect();
  57. PwLogger.WriteFeedback(Severity.PRI_CRITICAL, "Connected");
  58. //reader = new StreamReader(client);
  59. writer = new StreamWriter(client);
  60. }
  61. catch(Exception e)
  62. {
  63. PwLogger.WriteFeedback(Severity.PRI_CRITICAL, "Unable to connect to running TagCnf. Cannot display tag");
  64. }
  65. // string input = Console.ReadLine();
  66. if (String.IsNullOrEmpty(args[0]))
  67. {
  68. return;
  69. }
  70. writer.WriteLine(args[0]);
  71. writer.Flush();
  72. writer.Dispose();
  73. return;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement