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

时间:2016-08-08 12:52:03

标签: winforms f# delegates invoke 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()))

1 个答案:

答案 0 :(得分:3)

解决!当我所有必须做的事情是花费这么多时间尝试各种方法时,多么令人沮丧的是删除两个括号,转向

type ToggleVisibiltyDelegate() = delegate of unit -> unit

type ToggleVisibiltyDelegate = delegate of unit -> unit
相关问题