I am an F# noob and the learning curve has been steep, mostly because of not understanding why things are not working.
Here is some simple code that upd开发者_如何学JAVAates a progress bar that works in FSI (minus the Application.Run line).
open System
open System.Windows.Forms
open System.Drawing
open System.Threading
let form = new Form(TopMost = true, Visible=true)
let pb = new ProgressBar(Minimum = 0, Maximum = 15, Dock = DockStyle.Fill)
form.Controls.Add(pb)
let threadfunc () =
Thread.Sleep(5000)
for i = 0 to 15 do
Thread.Sleep(1000)
pb.Invoke(Action(fun _ -> pb.Value <- i)) |> ignore
let thread = new Thread(threadfunc)
thread.Start()
[<STAThread>]
do Application.Run(form)
This same code drawws a window with a progress bar that doesn't update and then crashes when I try to build the project and run it from the debugger.
I'm not sure why this works, but try adding Application.EnableVisualStyles()
before you create your form.
精彩评论