Smrf.NodeXL.ExcelTemplate.TaskAutomator.OpenWorkbookToAutomate C# (CSharp) Method

OpenWorkbookToAutomate() public static method

public static OpenWorkbookToAutomate ( String workbookPath, Int32 timeoutSeconds ) : System.Boolean
workbookPath String
timeoutSeconds System.Int32
return System.Boolean
    OpenWorkbookToAutomate
    (
        String workbookPath,
        Int32 timeoutSeconds
    )
    {
        Debug.Assert( !String.IsNullOrEmpty(workbookPath) );

        Boolean bWorkbookClosedByItself = true;

        Process oProcess = Process.Start("Excel.exe",
            "\"" + workbookPath + "\"");

        if ( !oProcess.WaitForExit(timeoutSeconds * 1000) )
        {
            bWorkbookClosedByItself = false;

            try
            {
                oProcess.Kill();
                oProcess.WaitForExit();
            }
            catch
            {
                // It's possible that the process exited after WaitForExit()
                // returned, in which case the Kill() call will fail.  Ignore
                // the Kill() failure.
            }
        }

        oProcess.Close();

        return (bWorkbookClosedByItself);
    }