I have a piece of code that adds a row to the database when MailboxProcessor receives a message. It works correctly when running in fsi, but it freezes when compiling in exe. The script looks like this:
#r "../packages/Newtonsoft.Json/lib/net40/Newtonsoft.Json.dll" #r "../packages/SQLProvider/lib/FSharp.Data.SqlProvider.dll" open Newtonsoft.Json open FSharp.Data.Sql open System let [<Literal>] ResolutionPath = __SOURCE_DIRECTORY__ + "/../build/" let [<Literal>] ConnectionString = "Data Source=" + __SOURCE_DIRECTORY__ + @"/test.db;Version=3" // test.db is initialized as follows: // // BEGIN TRANSACTION; // CREATE TABLE "Events" ( // `id`INTEGER PRIMARY KEY AUTOINCREMENT, // `timestamp` DATETIME NOT NULL // ); // COMMIT; type Sql = SqlDataProvider< ConnectionString = ConnectionString, DatabaseVendor = Common.DatabaseProviderTypes.SQLITE, ResolutionPath = ResolutionPath, IndividualsAmount = 1000, UseOptionTypes = true > let ctx = Sql.GetDataContext() let agent = MailboxProcessor.Start(fun (inbox:MailboxProcessor<String>) -> let rec loop() = async { let! msg = inbox.Receive() match msg with | _ -> let row = ctx.Main.Events.Create() row.Timestamp <- DateTime.Now printfn "Submitting" ctx.SubmitUpdates() printfn "Submitted" return! loop() } loop() ) agent.Post "Hello"
When compiling in exe, "Submit" is printed, but then it freezes. If you want to try, the full code is on github here
source share