title: Updating ShowMessageAsync Progress Value From "External" Method
body: <p>I have a WPF C# app using the <a href="http://mahapps.com/" rel="nofollow noreferrer">MahApps.Metro UI</a> resources. I'm trying to tie the <a href="http://mahapps.com/controls/dialogs.html" rel="nofollow noreferrer">progress dialog</a> control to a method call from another class and manually increment the progress of the progress bar as the method is stepped through. </p>
  
  <p>I'm having trouble figuring out how I would program "We're at checkpoint 1 of method X - report back 25% complete. Now we're at checkpoint 2 of method X - report back 50% complete."</p>
  
  <p>The method in MainWindow.xaml.cs that initiates the ShowMessageAsync progress bar is shown here:</p>
  
  <pre><code>     private async void installThirdPartyUpdatesButton_Click(object sender, RoutedEventArgs e)
      {
          var app = ((FrameworkElement)sender).DataContext as Tuple&lt;ThirdPartyUpdate.InstalledApplicationFromRegistryScan, ThirdPartyUpdate.ManifestRequiredApplication, ThirdPartyUpdate.RequiredApplicationState&gt;;
  
          Button ThirdPartyInstallButton = sender as Button;
          ThirdPartyInstallButton.IsEnabled = false;
  
          var controller = await this.ShowProgressAsync("Please wait...", "Preparing update installation...");
          await Task.Delay(2000);
          controller.SetCancelable(false);
  
          if (app != null)
          {
              ThirdPartyUpdate.thirdPartyApplicationInstallWorkflow(app);
          }
  
          controller.SetProgress(.25);
          controller.SetMessage("Closing dependant processes...");
          await Task.Delay(2000);
          controller.SetProgress(.50);
          controller.SetMessage("Uninstalling legacy version...");
          await Task.Delay(2000);
          controller.SetProgress(.75);
          controller.SetMessage("Installing new version...");
          await Task.Delay(2000);
          controller.SetProgress(.100);
  
          await controller.CloseAsync();
          await this.ShowMessageAsync("Success!", "Update installed successfully.");
      }
  </code></pre>
  
  <p>The <code>controller.SetProgress</code> entries I have there presently are for illustrative purposes only to show my desired outcome. They render the following:</p>
  
  <p><img src="https://i.stack.imgur.com/CItkm.png" alt="enter image description here"></p>
  
  <p>What I really need is for this method:</p>
  
  <pre><code>ThirdPartyUpdate.thirdPartyApplicationInstallWorkflow(app);
  </code></pre>
  
  <p>to report back its progress as it hits certain sections of code. Here are the contents of that method in case it helps:</p>
  
  <pre><code> public static int thirdPartyApplicationInstallWorkflow(Tuple&lt;ThirdPartyUpdate.InstalledApplicationFromRegistryScan, ThirdPartyUpdate.ManifestRequiredApplication, ThirdPartyUpdate.RequiredApplicationState&gt; thirdPartyApp)
      {
          // 1. Close listed process
          // 2. Execute explicit uninstall
          // 3. Execute WMI uninstall
          // 4. Execute install/command          
  
          writeEvent(EventLogEntryType.Information, "Beginning execution of: " + thirdPartyApp.Item2.Name + " job.", "Third Party Update");
  
          //Close processes prior to upgrade if needed
          closeProcesses(thirdPartyApp);
  
          //Execute explicit uninstall if needed
          uninstallExplicit(thirdPartyApp);
  
          //Execute WMI uninstall if needed
          uninstallWMI(thirdPartyApp);
  
          //Execute install
          if (!string.IsNullOrEmpty(thirdPartyApp.Item2.InstallString))
          {
              //String cleanup on comma placement so that a few different input styles are valid
              string cleanedstrInstall = thirdPartyApp.Item2.InstallString.Replace(", ", ",").Replace(" ,", ",").Replace(" , ", ",");
              List&lt;string&gt; strInstall = cleanedstrInstall.Split(',').ToList&lt;string&gt;();
              int installExitCode = 0;
              DateTime timeLaunched;
              DateTime timeCompleted;
  
              foreach (var install in strInstall)
              {
                  ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd.exe", "/c " + thirdPartyApp.Item2.InstallString);
                  // The following commands are needed to redirect the standard output.
                  // This means that it will be redirected to the Process.StandardOutput StreamReader.
                  procStartInfo.RedirectStandardOutput = true;
                  procStartInfo.RedirectStandardError = true;
                  procStartInfo.UseShellExecute = false;
                  // Do not create the black window.
                  procStartInfo.CreateNoWindow = true;
                  // Now we create a process, assign its ProcessStartInfo and start it
                  System.Diagnostics.Process proc = new System.Diagnostics.Process();
                  proc.StartInfo = procStartInfo;
                  writeEvent(EventLogEntryType.Information, "Attempting to launch upgrade: " + thirdPartyApp.Item2.InstallString, "Third Party Update");
                  timeLaunched = DateTime.UtcNow;
                  proc.Start();
                  string stderror = proc.StandardError.ReadToEnd();
                  proc.WaitForExit();
                  timeCompleted = DateTime.UtcNow;
                  if (proc.ExitCode == 0 || proc.ExitCode == 3010)
                  {
                      writeEvent(EventLogEntryType.Information, "Successfully completed upgrade from: " + thirdPartyApp.Item2.InstallString, "Third Party Update");
                  }
              }       
          }
          return 0;
      }
  </code></pre>