0

I have successfully installed MonoDevelop with the F# bindings (under Linux Arch).

If I try a simple HelloWorld with winforms, I get this strange behavior: the program compiles and builds successfully, but a moment after the window is loaded it just closes itself and the program returns with no error messages.

I checked the logs and it seems no error is thrown (except from the one discussed here: GLib-CRITICAL **: Source ID XXX was not found when attempting to remove it, which anyway seems unrelated).

The code for the program:

open System.Drawing
open System.Windows.Forms

[<EntryPoint>]
let main argv = 
    let form = new Form(TopMost = true, Text = "Hello World")
    form.Show()
    0 // return an integer exit code

If I try to run it through the interactive console, the window is sort of freezed: I can move it around, but I can't close it (have to shut down monodevelop in order to do so).

I also tried to compile it via terminal, using:

fsharpc Program.fs -pkg:dotnet.dll
mono Program.exe

but it behaves the same way as if I was running through MonoDevelop (window opens then shuts down). Other than that F# seems to work fine, I can run console programs without any problem.

I also tried to run a simple HelloWorld program with C# in MonoDevelop, and it just works fine.

Any tips?

Community
  • 1
  • 1
mp85
  • 422
  • 3
  • 17

1 Answers1

2

You need to start the forms event loop with something like

Application.Run(new Form())
John Palmer
  • 25,356
  • 3
  • 48
  • 67
  • Tried a moment ago, it worked just fine :) Thank you! I read it was not advisable to use Application.Run() in favor of form.Show(), but this seems to be definitely not the case. Oh well. – mp85 Oct 15 '15 at 10:52