我有一个代码,应在服务类中的一个在接收到一个事件通知委托:xamarin事件处理程序总是空
public class TestClass : ParentClass
{
public event EventHandler<string> MyDelegate;
public override void OnAction(Context context, Intent intent)
{
var handler = MyDelegate;
if (handler != null)
{
handler(this, "test");
}
}
}
我通过实例吧:
private TestClass mytest= new TestClass();
然后给它分配在功能之一:
mytest.MyDelegate+= (sender, info) => {
};
委托不会被调用。我已经通过调试程序,我看到代理正在分配,但类内的检查总是空的...不知道怎么回事...
怎么样给它分配在构造 - 机会是你的执行顺序是不正确的 –
@StenPetrov哦..你的意思是如果我做了一个任务后创建一个对象,它不会工作? – Ulterior
在你的'mytest.MyDelegate + = ...'和'OnAction'里面放置一个断点 - 看看先被命中了什么 –