2016-08-08 23 views
4

我試圖創建一些C#代碼的F#實現,它使用Dispatcher.BeginInvoke從另一個線程操縱UI。但是我努力讓代碼工作。F#Winforms Dispatcher BeginInvoke在運行時的委託問題

我已經嘗試了幾個不同的實現,但我總是看到「附加信息:運行時實現的委託方法的非法定義」。調用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())) 

回答

3

解決!多麼沮喪花了這麼多時間嘗試各種方法時,所有我需要做的就是刪除2個括號,把

type ToggleVisibiltyDelegate() = delegate of unit -> unit 

type ToggleVisibiltyDelegate = delegate of unit -> unit