【问题标题】:Windows Runtime (WP 8) out of process component and raising / subscription eventsWindows 运行时 (WP 8) 进程外组件和引发/订阅事件
【发布时间】:2015-06-15 22:03:06
【问题描述】:

我用自己的后台线程制作了进程外 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 文件 - 它们包含一些事件代码。

这个问题可能是什么原因造成的?

【问题讨论】:

    标签: c++ events windows-phone-8 out-of-process


    【解决方案1】:

    在本机模式下调试相同的代码时,我观察到“接口未注册”异常。 简短的搜索导致此参考:

    'Interface not Registered' error on ATL out-of-process callback interface

    但我使用 C++/CX,根本没有 IDL。 我查看了 ChatterBox 演示(这是我的 VoIP 应用程序的起点)——它们根本不使用 Windows 运行时事件。

    所以我停止了朝这个方向的尝试。

    另一种可能的方法是:

    • 使用自定义事件结构队列,从 C# 端轮询和处理此事件。
    • 使用在 C++/CX 中声明的接口作为事件处理程序。在 C# 端实现此接口。但是不确定它是否会将事件编组到主 UI 线程中。

    【讨论】:

    • 关于第二种方法的几句话 - 事件不会编组到主 UI 线程中。无论如何,这对我来说是可以接受的。
    猜你喜欢
    • 2013-01-18
    • 2022-01-08
    • 1970-01-01
    • 2016-02-04
    • 1970-01-01
    • 2013-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多