title: Updating parent process GUI on receiving Process.Exited event - WPF
body: <p>I am trying to launch a process within an application. The code below simply starts notepad on clicking the button of the main GUI. Now when the notepad is launched the button is disabled. I have subscribed to the Process.Exited even to receive notification when the notepad application closes. Once the notification is received I would like to re-enable the button again. </p>
  
  <p>However, code crashed when I call the button1.IsEnabled = true; It seems to that Process.Exit is not a part of the main GUI thread and hence when i try to update GUI within that it crashed. Also when i am debugging I dont receive any exception saying I am trying to access main thread from outside or something. </p>
  
  <p>Is there a way to notify GUI when the child process exits?</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Data;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Imaging;
  using System.Windows.Navigation;
  using System.Windows.Shapes;
  using System.ComponentModel;
  using System.Diagnostics;
  
  namespace ProcessWatch
  {
      /// &lt;summary&gt;
      /// Interaction logic for MainWindow.xaml
      /// &lt;/summary&gt;
      public partial class MainWindow : Window
      {
          Process pp = null;
          public MainWindow()
          {
              InitializeComponent();
          }
  
          private void button1_Click(object sender, RoutedEventArgs e)
          {
              pp = new Process();
              pp.EnableRaisingEvents = true;
              pp.Exited += new EventHandler(pp_Exited);
              ProcessStartInfo oStartInfo = new ProcessStartInfo();
              oStartInfo.FileName = "Notepad.exe";
              oStartInfo.UseShellExecute = false;
              pp.StartInfo = oStartInfo;
              pp.Start();
              button1.IsEnabled = false;
          }
  
          void pp_Exited(object sender, EventArgs e)
          {
              Process p = sender as Process;
              button1.IsEnabled = true;               
          }
      }
  }
  </code></pre>