Here is sample code snippet.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
open System
open System.Windows.Forms
open System.Threading

type MainForm () as self =
    inherit Form()

    let lblHello = new Label(Text = "Hello", Height = 20, Dock = DockStyle.Top)
    let btnClickMe = new Button(Text = "Click Me", Height = 30, Width = 50, Dock = DockStyle.Bottom)

    let updateLabelText() =
        if lblHello.InvokeRequired then
            lblHello.Invoke(MethodInvoker(fun () -> lblHello.Text <- "World!")) |> ignore
        else
            lblHello.Text <- "World!"


    let clickHandler (e:EventArgs) =
        let thread = new Thread(updateLabelText)
        thread.IsBackground <- true
        thread.Start()

    do        
        btnClickMe.Click.Add(clickHandler)
        self.Controls.Add(lblHello)
        self.Controls.Add(btnClickMe)


[<STAThread>]
do
    let mf = new MainForm()
    Application.Run(mf)
By on 3/29/2011 1:38 AM ()

Thank you very much!!

By on 3/29/2011 5:32 AM ()

Take a look at Control.Invoke: [link:msdn.microsoft.com]

It is used in F# like this:

1
2
3
 

label.BeginInvoke(MethodInvoker( fun () -> label.Text <- "Hello" ))
By on 3/28/2011 10:15 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper