运行时的 F# Winforms Dispatcher BeginInvoke 委托问题

4

我尝试创建一个基于F#的实现,用来处理从不同线程操纵UI的C#代码中的Dispatcher.BeginInvoke。然而,我一直在努力让这段代码正常工作。

我尝试了几种不同的实现方式,但无论如何,在调用ToggleVisibility函数时总是会出现"Additional information: Illegal definition for runtime implemented delegate method."异常。

非常感谢您提供任何帮助。以下是代码:-

open System
open System.Drawing
open System.Windows.Forms

type ToggleVisibiltyDelegate() = delegate of unit -> unit

type NotifyWindow() as form =
    inherit Form()
    let label1 = new Label()
    do form.InitializeForm

    member this.ToggleVisibility () =

        if (this.Visible) then
            this.BeginInvoke(new ToggleVisibiltyDelegate(fun () -> this.Hide()))
        else
            this.BeginInvoke(new ToggleVisibiltyDelegate(fun () -> this.Show()))
1个回答

3
解决了!多么令人沮丧啊,我花费了很多时间尝试各种方法,而我只需要删除两个括号,就可以把以下代码转换成可运行的形式:
type ToggleVisibiltyDelegate() = delegate of unit -> unit

转换为

type ToggleVisibiltyDelegate = delegate of unit -> unit

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接