feat(lmxproxy): add STA thread with message pump for MxAccess COM callbacks

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Joseph Doherty
2026-03-22 18:00:24 -04:00
parent c96e71c83c
commit b6408726bc
7 changed files with 161 additions and 17 deletions

View File

@@ -13,7 +13,7 @@ namespace ZB.MOM.WW.LmxProxy.Host.MxAccess
/// <summary>
/// Subscribes to value changes for the specified addresses.
/// Stores subscription state for reconnect replay.
/// COM calls dispatched via Task.Run.
/// COM calls dispatched on the dedicated STA thread.
/// </summary>
public async Task<IAsyncDisposable> SubscribeAsync(
IEnumerable<string> addresses,
@@ -25,7 +25,7 @@ namespace ZB.MOM.WW.LmxProxy.Host.MxAccess
var addressList = addresses.ToList();
await Task.Run(() =>
await _staThread.RunAsync(() =>
{
lock (_lock)
{
@@ -40,7 +40,7 @@ namespace ZB.MOM.WW.LmxProxy.Host.MxAccess
_storedSubscriptions[address] = callback;
}
}
}, ct);
});
Log.Information("Subscribed to {Count} tags", addressList.Count);
@@ -63,7 +63,7 @@ namespace ZB.MOM.WW.LmxProxy.Host.MxAccess
{
var addressList = addresses.ToList();
await Task.Run(() =>
await _staThread.RunAsync(() =>
{
lock (_lock)
{
@@ -93,7 +93,7 @@ namespace ZB.MOM.WW.LmxProxy.Host.MxAccess
Log.Information("Recreating {Count} stored subscriptions after reconnect", subscriptions.Count);
await Task.Run(() =>
await _staThread.RunAsync(() =>
{
lock (_lock)
{