Skip to content

Conversation

@breyed
Copy link
Contributor

@breyed breyed commented Nov 2, 2025

  • Supports posting methods to the synchronization context to be dispatched from the message loop on the main thread.
  • Events are forwarded directly to the handler, except that events from background threads or configured to post are posted to the synchronization context.
  • When a task method completes, the status is posted on the synchronization context.
  • C# async/await uses the synchronization context by default, causing continuations to run on the main thread. .NET code that can run safely on a background thread can opt to do so with ConfigureAwait(false).

This commit eliminates background thread calls into FoxPro and C# continuations, avoiding race conditions and data tearing, and providing a deterministic runtime environment.

Copilot AI review requested due to automatic review settings November 2, 2025 11:50
@breyed breyed mentioned this pull request Nov 2, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds synchronization context support to wwDotNetBridge to enable proper thread marshaling between .NET and FoxPro. The key enhancement allows .NET events and async operations to be safely invoked on the FoxPro main thread, preventing reentrancy issues and enabling safe cross-thread communication.

Key changes:

  • Introduces FoxProSynchronizationContext to marshal callbacks to the FoxPro UI thread using Windows messages
  • Adds PostMethod and PostStaticMethod methods to queue method invocations instead of executing them immediately
  • Refactors EventSubscriber to directly invoke handler methods instead of using an async wait pattern

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
wwDotNetBridge.csproj Enables latest C# language features
wwDotNetBridge.cs Adds synchronization context infrastructure and splits invoke methods into immediate vs. posted execution paths
FoxProSynchronizationContext.cs New class that implements Windows message-based synchronization for FoxPro interop
EventSubscriber.cs Refactored to directly invoke handler methods with optional synchronization context posting
wwDotnetBridge.PRG Adds PostMethod/PostStaticMethod APIs and updates event subscription to use new EventSubscriber design
Comments suppressed due to low confidence (4)

DotnetBridge/Utilities/FoxProSynchronizationContext.cs:38

  • Poor error handling: empty catch block.
                try { postedEvent.handler(postedEvent.state); } catch { }

DotnetBridge/wwDotNetBridge.cs:770

  • Variable args may be null at this access as suggested by this null check.
                if (args[i] is ComValue)

DotnetBridge/wwDotNetBridge.cs:1038

  • Variable args may be null at this access as suggested by this null check.
                if (args[i] is ComValue)

DotnetBridge/Utilities/FoxProSynchronizationContext.cs:38

  • Generic catch clause.
                try { postedEvent.handler(postedEvent.state); } catch { }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@breyed breyed force-pushed the synchronization-context branch from ec5d259 to 10f867b Compare November 2, 2025 12:56
@breyed
Copy link
Contributor Author

breyed commented Nov 2, 2025

Since with this PR all code running in FoxPro runs on the main thread, the multithreading-related caveats in the documentation can be removed:

@breyed breyed force-pushed the synchronization-context branch 4 times, most recently from 30c3df0 to f01d7c0 Compare November 5, 2025 15:18
* Supports posting methods to the synchronization context to be dispatched from the message loop on the main thread.
* Events are forwarded directly to the handler, except that events from background threads or configured to post are posted to the synchronization context.
* When a task method completes, the status is posted on the synchronization context.
* C# async/await uses the synchronization context by default, causing continuations to run on the main thread. .NET code that can run safely on a background thread can opt to do so with `ConfigureAwait(false)`.

This commit eliminates background thread calls into FoxPro and C# continuations, avoiding race conditions and data tearing, and providing a deterministic runtime environment.
@breyed breyed force-pushed the synchronization-context branch from f01d7c0 to a878e7c Compare November 12, 2025 23:33
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.

1 participant