F#Winforms Dispatcher在运行时开始调用委派问题



我尝试创建一些C#代码的F#实现,该代码使用Dispatcher.BeginInvoke从不同的线程操作UI。然而,我正在努力让代码发挥作用。

我尝试了一些不同的实现,但在调用ToggleVisibility函数时,似乎总是会出现"附加信息:运行时实现的委托方法的非法定义"异常。

如有任何意见,我们将不胜感激。这是代码:-

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()))

已解决!花了这么多时间尝试各种方法,而我所要做的就是删除两个括号,打开,这是多么令人沮丧啊

type ToggleVisibiltyDelegate() = delegate of unit -> unit

进入

type ToggleVisibiltyDelegate = delegate of unit -> unit

最新更新