提问人:Nishan Dhungana 提问时间:6/30/2023 最后编辑:djvNishan Dhungana 更新时间:6/30/2023 访问量:57
C语言中不同类库与另一个类库的触发方法#
Trigger method of different class library from another class library in C#
问:
我有一个两类库 A 和 B。A 是用 VB 编写的,B 是用 C 编写的#
A 的引用为 B。因此,我无法在 A 类库上实例化 B 的方法。
现在我有一个场景,如果执行了 B 库的某个方法,那么也应该执行 A 库的某些方法。 请注意,这里我无法在 B 中调用 A 的方法,因为 B 已经在 A 中被引用。
我试图为此进行委托,但似乎不起作用
这是到目前为止尝试过的(这是从 ChatGPT 生成的代码,但不起作用)
public delegate void MethodExecutedEventHandler();
public class ClassB
{
public event MethodExecutedEventHandler MethodExecuted;
public void SomeMethod()
{
// Method logic here...
// Raise the event when the method is executed
MethodExecuted?.Invoke();
}
}
在A面
Public Class ClassA
Private WithEvents b As New ClassB()
Private Sub OnMethodExecuted() Handles b.MethodExecuted
' Method logic to be executed when the method in class B is executed
End Sub
End Class
SomeMethod
的 ClassB 由作业每分钟自动执行一次。所以当方法被执行时,我希望ClassA也被执行。SomeMethod
OnMethodExecuted
可以做到吗?
如果是这样,我该怎么做?
答: 暂无答案
评论