Skip to content

C# sample

A minimal console app that opens a SIDRA project, runs an analysis, and prints the level-of-service for every intersection.

Project setup

SidraSample.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0-windows</TargetFramework>
    <Platforms>x64</Platforms>
    <PlatformTarget>x64</PlatformTarget>
  </PropertyGroup>
  <ItemGroup>
    <COMReference Include="SIDRASolutions.SI.API.dll">
      <EmbedInteropTypes>true</EmbedInteropTypes>
    </COMReference>
  </ItemGroup>
</Project>

Program.cs

using SIDRASolutions.SI.API;

var apiType = Type.GetTypeFromProgID("SIDRASolutions.SI.API")
              ?? throw new InvalidOperationException("SIDRA Intersection COM API is not registered. See COM activation.");

var api = (ISIAPI)Activator.CreateInstance(apiType)!;

try
{
    api.OpenProject(@"C:\Samples\Demo.sip");

    var project = api.Project;
    Console.WriteLine($"Project: {project.Name}");

    api.Analysis.Run();

    var folders = project.SiteFolders;
    for (int f = 0; f < folders.Count; f++)
    {
        var folder = folders[f];
        for (int s = 0; s < folder.Sites.Count; s++)
        {
            var site = folder.Sites[s];
            for (int i = 0; i < site.Intersections.Count; i++)
            {
                var intersection = site.Intersections[i];
                Console.WriteLine($"  {intersection.Name}: LOS = {intersection.LevelOfService}");
            }
        }
    }
}
finally
{
    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(api);
}

[!IMPORTANT] Always release the COM object with Marshal.FinalReleaseComObject (or wrap in using with a custom IDisposable adapter). The .NET COM host keeps the SIDRA Intersection runtime alive until every reference is released.

Reading detailed outputs

The output collections live under ISIAPIIntersection.Output* and ISIAPILaneMovement.Output*. See the API reference for the full surface.