MenüHomeBlogMagic

C#, Start Process

Eine Funktion die ich so ziemlich jeder C# Applikation hinzuf├╝ge ist

/**
 * @brief Start a External Process with parameter
 * @param sApp: Application to start
 * @param sArg: Start Paramter for Application.
 * @param bWait: Wait for Execution? default true
 * @param bVisible: Show Application on screen? default false.
 * @return true if return code of application was 0 (success)
 */
static public bool StartProcess(string sApp, string sArg, bool bWait = true, bool bVisible = false)
{
  bool bRet = false;
  System.Diagnostics.Process process = new System.Diagnostics.Process();
  System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
  startInfo.FileName = sApp;
  startInfo.Arguments = sArg;
  // check if process should become a window to show
  if(bVisible == true)
    startInfo.WindowStyle = ProcessWindowStyle.Normal;
  else
    startInfo.WindowStyle = ProcessWindowStyle.Hidden;
  process.StartInfo = startInfo;
  process.Start();
  // check if we have to wait for process
  if(bWait == true)
    process.WaitForExit();
  if (process.ExitCode == 0)
    bRet = true;
  // return exit-state.
  return bRet;
}

Das ist meine Eierlegendewollmilchsau um Prozesse zu starten.

Permalink: https://adirmeier.de/Blog/ID_131
Tags: Blog, C#, Windowsvon am 2017-06-06