Composite UI 中发布/订阅如何使用?

zhxfzhxf1 zhxfzhxf1 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我想使用发布/订阅实现系统间(同一进程内)不同窗体之间的通信,但发现它不能正常工作。
之后,我做了一个简单的测试程序:
创建一个 windows application 项目,
在系统自动创建的Form1(类)上添加CompositeUI中事件代理的引用
标记发布、订阅。
Form1的代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Practices.CompositeUI;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeUI.EventBroker;
using Microsoft.Practices.CompositeUI.Utility;

namespace PS
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
OnTextChanged(tbPub.Text);
}
[EventSubscription("topic://EventBrokerQuickStart/TextChanged", Thread = ThreadOption.UserInterface)]
public void OnSensingTextChanged(object sender, DataEventArgs<string> e)
{
tbSub.Text = "sssss" + e.Data;
}

[EventPublication("topic://EventBrokerQuickStart/TextChanged", PublicationScope.Global)]
public event EventHandler<DataEventArgs<string>> TextChangedEvent;
private void OnTextChanged(string strText)
{
if (TextChangedEvent != null)
{
TextChangedEvent(this, new DataEventArgs<string>(strText));
}
}
}
}


在调试时,发现TextChangedEvent始终为null。
而MS 或者其他人提供的例子中对应物则 不是 null。
不知道,使用发布/订阅还需要有什么条件。


请各位高手赐教。
...全文
评论 2
收藏 已收藏
分享
返回顶部
zhxfzhxf1
C# 111,129 成员 642,539 内容