-
-
Notifications
You must be signed in to change notification settings - Fork 39
Add synchronization context #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
FoxProSynchronizationContextto marshal callbacks to the FoxPro UI thread using Windows messages - Adds
PostMethodandPostStaticMethodmethods to queue method invocations instead of executing them immediately - Refactors
EventSubscriberto 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
if (args[i] is ComValue)
DotnetBridge/wwDotNetBridge.cs:1038
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.
ec5d259 to
10f867b
Compare
|
Since with this PR all code running in FoxPro runs on the main thread, the multithreading-related caveats in the documentation can be removed:
|
30c3df0 to
f01d7c0
Compare
* 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.
f01d7c0 to
a878e7c
Compare
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.