Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- F# Display a WPF window asynchronously
- > let ui =
- let mk() =
- let wh = new ManualResetEvent(false)
- let application = ref null
- let start() =
- let app = Application()
- application := app
- ignore(wh.Set())
- app.Run() |> ignore
- let thread = Thread start
- thread.IsBackground <- true
- thread.SetApartmentState ApartmentState.STA
- thread.Start()
- ignore(wh.WaitOne())
- !application, thread
- lazy(mk());;
- val ui : Lazy<Application * Thread> = <unevaluated>
- > let spawn : ('a -> 'b) -> 'a -> 'b =
- fun f x ->
- let app, thread = ui.Force()
- let f _ =
- try
- let f_x = f x
- fun () -> f_x
- with e ->
- fun () -> raise e
- let t = app.Dispatcher.Invoke(DispatcherPriority.Send, System.Func<_, _>(f), null)
- (t :?> unit -> 'b)();;
- val spawn : ('a -> 'b) -> 'a -> 'b
- let openAWindow text =
- DisplayWindow().SetMessage text
- spawn openAWindow text
Advertisement
Add Comment
Please, Sign In to add comment