Reputation: 71
I have tried to create an F# implementation of some C# code that uses Dispatcher.BeginInvoke to manipulate the UI from a different thread. However I'm struggling to get the code to work.
I've tried a few different implementations but I always seem to get a "Additional information: Illegal definition for runtime implemented delegate method." exception when calling the ToggleVisibility function.
Any input would be very gratefully received. Here is the code:-
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()))
Upvotes: 4
Views: 189
Reputation: 71
Solved! How frustrating to have spent so much time trying various methods when all I had to do was delete two parentheses, turning
type ToggleVisibiltyDelegate() = delegate of unit -> unit
into
type ToggleVisibiltyDelegate = delegate of unit -> unit
Upvotes: 3