Analysis in the SPACE GASS API is asynchronous — when you start
an analysis, the API returns immediately with a run ID. You then poll
for progress until the run completes. This guide covers the common
patterns from simple scripting to advanced multi-run monitoring.
How It Works
Start an analysis — returns an AnalysisRun with a runId and initial status
Poll the run status using the runId at regular intervals
Check for a terminal status: Completed, Failed, or Cancelled
Query results once completed
Simple Script — Wait for Completion
Most scripts just need to run an analysis and wait. Here is a simple
helper that polls until the analysis finishes, then returns the
final status:
using SpaceGassApi;using SpaceGassApi.Models;var client = SpaceGassApiClient.CreateClient("http://localhost:34560");// Open a project and run linear static analysisawait client.Job.Open.PostAsync( new OpenJobRequest { FilePath = @"C:\Projects\MyStructure.sg" });var run = await client.Job.Analysis.Static.RunLinear.PostAsync( new StaticSettingsUpdate());// Poll until completevar result = await WaitForCompletion(client, run.RunId.Value);Console.WriteLine($"Analysis {result.Status} in {result.ElapsedTime}");if (result.Status == RunStatus.Completed){ // Query results... var reactions = await client.Job.Query.Analysis.Static.NodeReactions.GetAsync(); Console.WriteLine($"Got {reactions.Results.Count} reactions");}await client.Job.Close.PostAsync();// --- Helper: poll until terminal state ---static async Task<AnalysisRun> WaitForCompletion( SpaceGassApiClient client, Guid runId, int pollMs = 500){ while (true) { await Task.Delay(pollMs); var status = await client.Job.Analysis.Runs[runId].GetAsync(); if (status.Status is RunStatus.Completed or RunStatus.Failed or RunStatus.Cancelled) { return status; } }}
The WaitForCompletion helper turns the async polling into a simple
blocking call — your script just waits until the analysis is done
before moving on. This is the pattern you will use most often in
scripts.
Pre-Check with Analysis Info
Before running an analysis, you can call the Info endpoint to see
which load cases already have results — and which still need to be
analysed. This avoids re-running cases that are already complete,
which saves time on large models.
Analysis.Static.Info (and the equivalent Buckling.Info and
DynamicFrequency.Info) returns:
Field
Description
HasResults
true if any case has stored results for this analysis type
LoadCases
Per-case breakdown — each entry has a LoadCase Id and HasResults flag
NotAnalyzed
SG list-format string of case Ids that have not been analysed — ready to pass straight into a run request
Check which cases have been analysed
var info = await client.Job.Analysis.Static.Info.GetAsync();Console.WriteLine($"Has any results: {info.HasResults}");foreach (var c in info.LoadCases!){ Console.WriteLine($" LC {c.LoadCase}: {(c.HasResults == true ? "analysed" : "not analysed")}");}if (info.NotAnalyzed != null) Console.WriteLine($"Not analysed: {info.NotAnalyzed}");
Filter to a specific range
Pass a loadCases filter to check a subset. The NotAnalyzed field
returns only the intersection of your filter with the not-analysed
set — you can feed it directly into the run request.
// Check cases 1 through 10var info = await client.Job.Analysis.Static.Info.GetAsync( config => config.QueryParameters.LoadCases = "1-10");if (info.NotAnalyzed != null){ Console.WriteLine($"Cases 1-10 not yet analysed: {info.NotAnalyzed}"); // Run only the missing cases var run = await client.Job.Analysis.Static.RunLinear.PostAsync( new StaticSettingsUpdate { LoadCases = info.NotAnalyzed }); var result = await WaitForCompletion(client, run.RunId.Value); Console.WriteLine($"Analysis {result.Status}");}else{ Console.WriteLine("Cases 1-10 are all analysed — nothing to run.");}
This pattern is especially useful in automation workflows where
a model is re-analysed incrementally — new load cases are added and
only the missing ones need to be run, leaving existing results intact.
Running Multiple Analyses in Sequence
The API processes analysis runs in a queue. You can start multiple
analyses and they will execute in order. Poll the last run ID to
know when all analyses are complete:
// Queue three analysis typesvar staticRun = await client.Job.Analysis.Static.RunLinear.PostAsync( new StaticSettingsUpdate());Console.WriteLine($"Queued linear static: {staticRun.RunId}");var bucklingRun = await client.Job.Analysis.Buckling.Run.PostAsync( new BucklingSettingsUpdate());Console.WriteLine($"Queued buckling: {bucklingRun.RunId}");var dynamicRun = await client.Job.Analysis.DynamicFrequency.Run.PostAsync( new DynamicFrequencySettingsUpdate());Console.WriteLine($"Queued dynamic frequency: {dynamicRun.RunId}");// Wait for each in ordervar staticResult = await WaitForCompletion(client, staticRun.RunId.Value);Console.WriteLine($"Static: {staticResult.Status} ({staticResult.ElapsedTime})");var bucklingResult = await WaitForCompletion(client, bucklingRun.RunId.Value);Console.WriteLine($"Buckling: {bucklingResult.Status} ({bucklingResult.ElapsedTime})");var dynamicResult = await WaitForCompletion(client, dynamicRun.RunId.Value);Console.WriteLine($"Dynamic: {dynamicResult.Status} ({dynamicResult.ElapsedTime})");
Monitoring Progress
For longer analyses you may want to display progress as it runs.
The AnalysisRun.Progress object provides step labels, iteration
percentages, and load case status:
var lastStep = -1;while (true){ await Task.Delay(500); var status = await client.Job.Analysis.Runs[runId].GetAsync(); if (status.Progress != null) { var p = status.Progress; var stepInfo = $"Step {p.CurrentStep}/{p.TotalSteps}"; // Print step label when it changes if (p.CurrentStep != lastStep && p.StepLabels != null) { var idx = p.CurrentStep ?? 0; if (idx < p.StepLabels.Count && !string.IsNullOrEmpty(p.StepLabels[idx])) Console.WriteLine($" [{stepInfo}] {p.StepLabels[idx]}"); lastStep = p.CurrentStep ?? -1; } // Overwrite current line with live progress Console.Write($"\r {stepInfo} | {p.IterationPercentage}%"); if (p.LoadCaseStatus != null) Console.Write($" | {p.LoadCaseStatus}"); Console.Write("".PadRight(20)); } if (status.Status is RunStatus.Completed or RunStatus.Failed or RunStatus.Cancelled) { Console.WriteLine(); Console.WriteLine($"Analysis {status.Status} in {status.ElapsedTime}"); if (status.Warnings?.Count > 0) Console.WriteLine($" Warnings: {status.Warnings.Count}"); if (status.ErrorMessage != null) Console.WriteLine($" Error: {status.ErrorMessage}"); break; }}
Cancelling a Run
You can cancel a running or queued analysis by calling DELETE on
the run:
The run transitions to Cancelling and then Cancelled once the
solver has stopped.
Analysis Run Lifecycle
Status
Description
Queued
Run is waiting in the queue
Running
Analysis is actively executing
Cancelling
Cancellation requested, waiting for solver to stop
Completed
Analysis finished successfully — results are available
Failed
Analysis encountered an error — check errorMessage
Cancelled
Analysis was cancelled before completion
Advanced: Real-Time Monitoring Application
For a full example of an interactive monitoring application that
tracks multiple concurrent runs with live progress bars, elapsed
timers, and error/warning display, see the
AnalysisMonitor WPF example
in the repository.