我尝试创建一个基于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()))