开发者

Code that runs correctly in FSI doesn't run correctly when project is run

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜