none
Event does not trigger RRS feed

  • Question

  • Hello,

    I have two applications - app1, app2. app1 constantly write to stdout via console with some certain formatted messages; app2 will read each of these messages, when it detects certain message, it will execute some function (here I simplify the function as writing a "Succeed!" to its textbox.text). I checked that the messages are successfully read by app2, but the function is not triggered. I have omitted less important code in the following.

    Here is the code for app1:

    [DllImport("Kernel32.dll")]
    static extern Boolean AllocConsole();
    
    private void button1_Click(object sender, RoutedEventArgs e)
    {
        k = 0;
        m = 1;
        while (true)
        {
            k++;
            if (k % 150000000 == 0)
            {
                 AllocConsole();
                 Console.WriteLine("m = {0};", m);
                 m++;
            }
        }
    }

    Here is the code for app2:

        public partial class Window1 : Window    

    {

    public bool gtReady; // and do something private void Window_Loaded(object sender, RoutedEventArgs e) { gazeStateMonitor gsMonitor = new gazeStateMonitor(); gazeListener(gsMonitor); gsMonitor.gazeProc(); } private void gazeListener(gazeStateMonitor gsMonitor) { gsMonitor.OnGazeReady += new gazeStateMonitor.gazeReady(this.execute); } // actual function that executes protocols private void execute(object sender, EventArgs e) { gtReady = true; //do things this.textBox1.Text = "Succeed!"; } } // class to monitor the stdout from app1 class gazeStateMonitor { string fileName = @"C:app1.exe"; public delegate void gazeReady(object sender, EventArgs e); public event gazeReady OnGazeReady; public void gazeProc() { Process p = new Process(); p.StartInfo.FileName = fileName; p.StartInfo.CreateNoWindow = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardInput = true; p.StartInfo.UseShellExecute = false; p.OutputDataReceived += new DataReceivedEventHandler(WriteOutput); p.Start(); //stream p.BeginOutputReadLine(); } public void WriteOutput(object sender, DataReceivedEventArgs outLine) { Match match = Regex.Match(outLine.Data, @"m = 2;"); if (match.Success) { // show something OnGazeReady(this, outLine); } } }


    I am new to event. Thank you for your time in advance.

    Sean



    • Edited by seanlawson Monday, July 8, 2013 6:25 AM
    Monday, July 8, 2013 6:22 AM

Answers

  • Thanks, actually those are two events, I meant the OnGazeReady Event didn't trigger.

    However, I figured it out last night, the event does triggered, the reason I didn't know is that " this.textBox1.Text = "Succeed!";" doesn't work. It warns me it is used by other process. Anyway, it's a different question now.

    • Marked as answer by seanlawson Tuesday, July 9, 2013 4:59 PM
    Tuesday, July 9, 2013 4:59 PM

All replies

  • Hi,

    I don't understand which function don't trigger, from your app1 ,i know that there is an endless loop. from your  app2 ,I  think that in OnGazeReadyfunction and  WriteOutput(objectsender,DataReceivedEventArgsoutline),their parameter aren't  compatible. I suggest you to try  setting break point and then debug step by step.


    Tuesday, July 9, 2013 7:51 AM
  • Thanks, actually those are two events, I meant the OnGazeReady Event didn't trigger.

    However, I figured it out last night, the event does triggered, the reason I didn't know is that " this.textBox1.Text = "Succeed!";" doesn't work. It warns me it is used by other process. Anyway, it's a different question now.

    • Marked as answer by seanlawson Tuesday, July 9, 2013 4:59 PM
    Tuesday, July 9, 2013 4:59 PM