Windows 运行时 (WP 8) 进程组件外和引发/订阅事件
Windows Runtime (WP 8) out of process component and raising / subscription events
我制作了进程外 WR/WP8 组件,它有自己的后台线程。它在内部处理 SIP 堆栈并在后台线程中运行。它是从 ChatterBox MSDN 示例中修改的代码。
https://code.msdn.microsoft.com/windowsapps/ChatterBox-VoIP-sample-app-b1e63b8b
最后几天我添加了委托以从组件引发事件。
在 C++/CX 中是:
public delegate void OnLogMessage(Platform::String^ msg);
public ref class Logger sealed
{
public:
Logger();
virtual ~Logger();
void FlushLog();
event OnLogMessage^ OnLogMessage;
};
C# 代码中有事件订阅:
BackgroundProcessController.Instance.Logger.OnLogMessage += new IntTalk.OnLogMessage(mLogger_OnLogMessage);
构建正常。
但在调试期间我看到异常:
A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll
Additional information: Interface not registered (Exception from HRESULT: 0x80040155)
If there is a handler for this exception, the program may be safely continued.
已生成代理存根 DLL。我检查了 .h/.c 文件 - 它们包含一些事件代码。
导致此问题的原因是什么?
在本机模式下调试相同代码时,我观察到 "Interface not registered" 异常。
简短搜索得到了这个参考:
'Interface not Registered' error on ATL out-of-process callback interface
但我使用 C++/CX,根本没有 IDL。
我检查了 ChatterBox 演示(这是我的 VoIP 应用程序的起点)——它们根本不使用 Windows 运行时事件。
所以我停止了往这个方向的尝试。
另一种可能的方式是:
- 使用自定义事件结构队列,从 C# 端轮询和处理此事件。
- 使用在 C++/CX 中声明的接口作为事件处理程序。在 C# 端实现此接口。但是不确定它是否会将事件编组到主 UI 线程中。
我制作了进程外 WR/WP8 组件,它有自己的后台线程。它在内部处理 SIP 堆栈并在后台线程中运行。它是从 ChatterBox MSDN 示例中修改的代码。 https://code.msdn.microsoft.com/windowsapps/ChatterBox-VoIP-sample-app-b1e63b8b
最后几天我添加了委托以从组件引发事件。 在 C++/CX 中是:
public delegate void OnLogMessage(Platform::String^ msg);
public ref class Logger sealed
{
public:
Logger();
virtual ~Logger();
void FlushLog();
event OnLogMessage^ OnLogMessage;
};
C# 代码中有事件订阅:
BackgroundProcessController.Instance.Logger.OnLogMessage += new IntTalk.OnLogMessage(mLogger_OnLogMessage);
构建正常。
但在调试期间我看到异常:
A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll
Additional information: Interface not registered (Exception from HRESULT: 0x80040155)
If there is a handler for this exception, the program may be safely continued.
已生成代理存根 DLL。我检查了 .h/.c 文件 - 它们包含一些事件代码。
导致此问题的原因是什么?
在本机模式下调试相同代码时,我观察到 "Interface not registered" 异常。 简短搜索得到了这个参考:
'Interface not Registered' error on ATL out-of-process callback interface
但我使用 C++/CX,根本没有 IDL。 我检查了 ChatterBox 演示(这是我的 VoIP 应用程序的起点)——它们根本不使用 Windows 运行时事件。
所以我停止了往这个方向的尝试。
另一种可能的方式是:
- 使用自定义事件结构队列,从 C# 端轮询和处理此事件。
- 使用在 C++/CX 中声明的接口作为事件处理程序。在 C# 端实现此接口。但是不确定它是否会将事件编组到主 UI 线程中。