-1
我不确定这是否是正确的标题,但我会解释。 我有两个类,Test
和Boo
,由我自己编写。第三类叫Manager
也在那里。我想启动一个Manager
对象,然后监听类Test
中方法的更改。事件侦听通知其他事件
public class Test
{
Manager manager;
public event EventHandler NotifyMe;
public Test()
{
manager = new Manager();
}
public void start()
{
manager.ChangedState += (sender, e) =>
{
Console.WriteLine(e.State);
NotifyMe(this, e);
}
}
}
然后我有类Boo
与方法foo()
当我要听我的NotifyMe
事件,最终得到如果manager
对象已经解雇了ChangedState
。
public class Boo
{
public void foo()
{
Test test = new Test();
test.start();
test.NotifyMe += (sender, e) =>
{
Console.WriteLine("Manager has changed the state");
}
}
}
这仅是第一次,当我执行start()
和我的想法是监听的manager.ChangedState
通过test.NotifyMe
所有的时间。这是要走的路吗?
你需要在调用start之前连接你的事件处理程序(test.NotifyMe)吗? – 2014-09-11 11:44:21