Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to know if Process.Start() is successful?
    primarykey
    data
    text
    <p>I've tried two different methods for starting a process.</p> <p><strong>The first</strong></p> <p>The definition is defined as parameters to the Start method:</p> <p><code>System.Diagnostics.Process.Start("excel", string.Format("\"{0}\"", ExcelFileBox.Text.ToString()));</code></p> <p>My thoughts:</p> <p>This one starts just fine, but I don't know how to get feedback from it. </p> <p><strong>The second</strong> </p> <p>I started looking into <code>ProcessStartInfo</code> because I want to know if Excel started successfully or not--for instance, while it's very likely it exists on the user's machine, there's no guarantee and it would be silly for me to indicate to the user that it's started successfully when it hasn't.</p> <pre><code>System.Diagnostics.ProcessStartInfo startinfo = new System.Diagnostics.ProcessStartInfo { FileName = "excel", Arguments = string.Format("\"{0}\"", ExcelFileBox.Text.ToString()), ErrorDialog = true, UseShellExecute = false, WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) }; try { System.Diagnostics.Process.Start(startinfo); } catch (Exception err) { Console.WriteLine(err.Message); } </code></pre> <p>My thoughts:</p> <p>This gives the error: "The system cannot find the file specified", but it's unclear whether it means the Excel application or my file. In any case, while I appreciate the error message ability, I shouldn't be receiving out at the moment.</p> <p>Thought, suggestions, ideas on how to know if this happened successfully?</p> <p><strong>Solved</strong></p> <p>I put the first way of starting a process into a try-catch and it works beautifully.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload