Skip to content

Conversation

@eozdil174
Copy link
Contributor

Summary

Adds SimConnect_SubscribeToSystemEvent handling to the SimConnectClient

Usage example:

// The EventId can be any number
client.SystemEventReceived += (sender, e) =>
{
    switch (e.EventId)
    {
        case 100:
            Console.WriteLine("Simulator is running or a flight has started!");
            break;
    }
}

// Subscribe to the event (will start listening immediately)
await client.SubscribeToEventAsync("4sec", 100);

Changes Made

  • Added new SimConnectClient.SubscribeToEventAsync method for event subscription
  • Added a basic Test to check the functionality of the new Event system

Additional Information

Some background on why I've implemented this:

I am a developer for a Virtual airline and have started using your library during my refactoring away from FSUIPC for Sim communication, we check for when a user has paused their sims to various actions. While implementing the new code I've noticed the only way to reliably check the pause state on MSFS is to use these Simconnect System Events. Which wasn't supported from what I could see so I decided to make a small PR to add the implementation.

Let me know if anything needs changing or if there is any points you would like to discuss.

Author Information

Discord Username: eoz.dll


Checklist:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

@greptile-apps
Copy link

greptile-apps bot commented Dec 28, 2025

Greptile Summary

  • Adds SimConnect system event subscription functionality to enable monitoring of simulator state changes like pause/unpause events through a new SubscribeToEventAsync method and SystemEventReceived event
  • Introduces SimSystemEventReceivedEventArgs class for strongly-typed system event data handling and integrates system event processing into the existing message handling pipeline
  • Includes comprehensive test coverage with new SystemEventSubscriptionTests class and command-line filtering option for system event tests

Important Files Changed

Filename Overview
src/SimConnect.NET/SimConnectClient.cs Core implementation adding SubscribeToEventAsync method, SystemEventReceived event, and ProcessSystemEvent message handling
src/SimConnect.NET/Events/SimSystemEventReceivedEventArgs.cs New EventArgs class providing strongly-typed container for system event data with EventId and Data properties
tests/SimConnect.NET.Tests.Net8/Tests/SystemEventSubscriptionTests.cs New test class validating system event subscription functionality using "4sec" system events
tests/SimConnect.NET.Tests.Net8/Tests/TestRunner.cs Updated test runner to include SystemEventSubscriptionTests and added --test-events command line option

Confidence score: 4/5

  • This PR is safe to merge with minor review recommended due to well-structured implementation following existing patterns
  • Score reflects solid architecture, proper error handling, and comprehensive testing, with only minor documentation formatting issues found
  • Pay close attention to SimSystemEventReceivedEventArgs.cs for the trailing period in XML comment that should be removed for consistency

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Comments (3)

  1. src/SimConnect.NET/Events/SimSystemEventReceivedEventArgs.cs, line 11-12 (link)

    syntax: Line 11 has a trailing period after 'identifier and' in the XML comment

  2. tests/SimConnect.NET.Tests.Net8/Tests/SystemEventSubscriptionTests.cs, line 31-40 (link)

    style: Event handler should be unsubscribed in a finally block to prevent memory leaks in case of exceptions

  3. src/SimConnect.NET/SimConnectClient.cs, line 358 (link)

    syntax: The return type description says 'A task representing the event' but should say 'A task representing the subscription operation'

4 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

@AussieScorcher AussieScorcher changed the base branch from main to 0.1.18 December 29, 2025 03:53
@AussieScorcher AussieScorcher merged commit a83f8eb into stopbars:0.1.18 Dec 29, 2025
3 checks passed
AussieScorcher added a commit that referenced this pull request Dec 29, 2025
* Add SimConnect_SubscribeToSystemEvent handling (#15)

* feat: add system event subscription and management features in version 0.1.18

- Implemented subscription to simulator system events via `SimConnectClient.SubscribeToEventAsync`.
- Added typed event handlers for frame, filename, object add/remove, and extended EX1 system events.
- Introduced helper methods for managing event states: `SetSystemEventStateAsync` and `UnsubscribeFromEventAsync`.
- Enhanced performance by optimizing message processing and memory allocation in SimVar setters.
- Updated bundled `SimConnect.dll` to the latest SDK version.
- Added tests for system event subscription and state management.

---------

Co-authored-by: Eren Özdil <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants