如何处理 VB.Net 中的 F# 事件?
How can I handle F# events in VB.Net?
我正在按照 Don Syme 在 here 上建议的方法引发事件并在 GUI 中处理它。
我按如下方式创建了我的活动
let progressReport = new Event<int>()
并曝光如下
[<CLIEvent>]
member this.ReportProgress = progressReport.Publish
在我的 VB.net 代码中,我可以看到事件,甚至可以响应它。但是,如果我忽略 int 参数,我只能响应它。我的有效代码是
Private Sub test() Handles calcAgent.ReportProgress
prog.Value += 1
End Sub
如果我尝试将其更改为
Private Sub test(i As int) Handles calcAgent.ReportProgress
prog.Value += 1
End Sub
它不会编译并给出原因"Method 'test' cannot handle 'ReportProgress' because they do not have a compatible signature."
sender:obj * args:'T -> unit
的 FSharp.Control.FSharpHandler<'T>
has the signature 类型,这意味着附加到它的委托必须有两个参数 - sender:obj
和 args:'T
。
在你的例子中,'T
是 int
,所以你的处理程序应该是:
Private Sub test(sender As Object, i As int) Handles calcAgent.ReportProgress
prog.Value += 1
End Sub
我正在按照 Don Syme 在 here 上建议的方法引发事件并在 GUI 中处理它。 我按如下方式创建了我的活动
let progressReport = new Event<int>()
并曝光如下
[<CLIEvent>]
member this.ReportProgress = progressReport.Publish
在我的 VB.net 代码中,我可以看到事件,甚至可以响应它。但是,如果我忽略 int 参数,我只能响应它。我的有效代码是
Private Sub test() Handles calcAgent.ReportProgress
prog.Value += 1
End Sub
如果我尝试将其更改为
Private Sub test(i As int) Handles calcAgent.ReportProgress
prog.Value += 1
End Sub
它不会编译并给出原因"Method 'test' cannot handle 'ReportProgress' because they do not have a compatible signature."
sender:obj * args:'T -> unit
的 FSharp.Control.FSharpHandler<'T>
has the signature 类型,这意味着附加到它的委托必须有两个参数 - sender:obj
和 args:'T
。
在你的例子中,'T
是 int
,所以你的处理程序应该是:
Private Sub test(sender As Object, i As int) Handles calcAgent.ReportProgress
prog.Value += 1
End Sub