简体   繁体   English

从另一个DLL(或应用程序)触发DLL事件

[英]Fire DLL event from another DLL (or Application)

I have 2 projects. 我有2个项目。 In the first: 在第一个中:

public delegate _Event(int code);
public event _Event TestEvent;

now I want to do something like this in my second project 现在我想在第二个项目中做类似的事情

public void TestFunc()
{
   TestEvent(11); //Project1.MyClass.TestEvent(11);
}

namely I want to fire Project1's event form Project2. 即我要触发Project1的事件表单Project2。 Can anybody help me about this? 有人可以帮我吗?

1.You're missing the return type on the delegate. 1.您缺少委托的返回类型。

2.You can fire the event from within the declaring type only. 2.您只能在声明类型内触发事件。 What you can do is declare a public method on the type which declares the event which fires it. 您可以做的是在声明引发事件的事件的类型上声明一个公共方法。

public delegate void _Event(int code);
public event _Event TestEvent;
public void FireEvent(int val){TestEvent(val);}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM