Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public delegate void EventHandler();
- class someClass
- {
- WrapperForm dlg = null;
- StreamReader reader ;
- System.Timers.Timer timer;
- static NamedPipeServerStream server;
- public void CallToChildThread(Object stateInfo)
- {
- AutoResetEvent autoEvent = (AutoResetEvent)stateInfo;
- if (server.IsConnected)
- {
- string tempString = reader.ReadLine();
- server.Flush();
- //Fire event
- _show.Invoke();
- }
- else
- {
- server.WaitForConnectionAsync();
- }
- autoEvent.Set();
- }
- public someClass()
- {
- public static event EventHandler _show;
- server = new NamedPipeServerStream("TagCnfConnection", PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
- server.WaitForConnectionAsync();
- initializeDialog(); // Initialize the dialog. Standard new
- reader = new StreamReader(server);
- var autoEvent = new AutoResetEvent(false);
- var stateTimer = new System.Threading.Timer(CallToChildThread,
- autoEvent, 1000, 250);
- _show += new EventHandler(eventCheck);
- }
- void eventCheck()
- {
- //If some condition
- dlg.ShowDialog();
- }
- }
- if (args == null)
- {
- PwLogger.WriteFeedback(Severity.PRI_CRITICAL, "No Aargument");
- return; // return if not
- }
- else //Do the work
- {
- StreamReader reader = null;
- StreamWriter writer = null;
- try
- {
- NamedPipeClientStream client = new NamedPipeClientStream("TagCnfConnection");
- client.Connect();
- PwLogger.WriteFeedback(Severity.PRI_CRITICAL, "Connected");
- //reader = new StreamReader(client);
- writer = new StreamWriter(client);
- }
- catch(Exception e)
- {
- PwLogger.WriteFeedback(Severity.PRI_CRITICAL, "Unable to connect to running TagCnf. Cannot display tag");
- }
- // string input = Console.ReadLine();
- if (String.IsNullOrEmpty(args[0]))
- {
- return;
- }
- writer.WriteLine(args[0]);
- writer.Flush();
- writer.Dispose();
- return;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement