Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/Elmish.WPF/WpfProgram.fs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,30 @@ module WpfProgram =
Application () |> ignore
Application.Current.MainWindow <- window

let runElmishLoopOnBackgroundThread window program =

let elmishThread =
System.Threading.Thread(
System.Threading.ThreadStart(fun () ->
startElmishLoop window program
System.Windows.Threading.Dispatcher.Run()))
elmishThread.Name <- "ElmishDispatchThread"
elmishThread.Start()

elmishThread

let shutdownElmishBackgroundThread thread =
System.Windows.Threading.Dispatcher.FromThread(thread).InvokeShutdown()
thread.Join()

let runWindowThreaded window program =
initializeApplication window
let elmishThread = runElmishLoopOnBackgroundThread window program
window.Show ()
let exitCode = Application.Current.Run window
shutdownElmishBackgroundThread elmishThread
exitCode


/// Starts the Elmish and WPF dispatch loops. Will instantiate Application and set its
/// MainWindow if it is not already running, and then run the specified window. This is a
Expand Down