private static async Task<ProfileResultInfo> ExecuteProfilingCommandAsync(string arguments, ITracer tracer) { MemoryStream outputStream = null; MemoryStream errorStream = null; try { tracer.Step("ProcessName:" + _processName + " arguments:" + arguments); var exe = new Executable(_processName, Path.GetDirectoryName(_processName), TimeSpan.FromSeconds(ProcessExitTimeoutInSeconds)); outputStream = new MemoryStream(); errorStream = new MemoryStream(); tracer.Step("Path:" + exe.Path + " working directory:" + exe.WorkingDirectory); int exitCode = await exe.ExecuteAsync(tracer, arguments, outputStream, errorStream); string output = GetString(outputStream); string error = GetString(errorStream); tracer.Step(output); if (exitCode != 0) { tracer.TraceError(string.Format(CultureInfo.InvariantCulture, "Starting process {0} failed with the following error code '{1}'.", _processName, exitCode)); return new ProfileResultInfo(HttpStatusCode.InternalServerError, "Profiling process failed with the following error code: " + exitCode); } else if (!string.IsNullOrEmpty(error)) { tracer.TraceError(error); return new ProfileResultInfo(HttpStatusCode.InternalServerError, "Profiling process failed with the following error: " + error); } return new ProfileResultInfo(HttpStatusCode.OK, string.Empty); } catch (Exception ex) { tracer.TraceError(ex); return new ProfileResultInfo(HttpStatusCode.InternalServerError, ex.Message); } finally { if (outputStream != null) { outputStream.Dispose(); } if (errorStream != null) { errorStream.Dispose(); } } }