none
EnableRaisingEvents RRS feed

  • Question

  • Hi

    I have a windows console application and would like to be able to catch events such as when the <ctrl><break> and <ctrl><C> keys are pressed. Can someone please point me in the correct direction? The following is a sample code of what I currently have:

        public void execute_command(string executable, string args)
        {
          if (_p == null)
          {
            ProcessStartInfo pi = new ProcessStartInfo(executable, args);
            pi.Arguments = args;
    
            _p = Process.Start(pi);
            _p.EnableRaisingEvents = true;
            _p.Exited += new System.EventHandler(_p_Exited);
          }
          else if (_p != null)
          {
            _p.Kill();
            _p.Dispose();
            _p = null;
          }
        }
    
        void _p_Exited(object sender, System.EventArgs e)
        {
          MessageBox.Show("Process finished.");
          _p.Dispose();
          _p = null;
        }

    As you can see I am using

    _p.EnableRaisingEvents = true;

    but I read through some documentation explaining that this call will only enable catching the EXIT signal. As explained earlier, I would like to catch more signals...

     

     

     

     

     

     

     

     

     

     

     

     

     

    Friday, April 23, 2010 9:55 AM

Answers