Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7076633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:19:19+00:00 2026-05-28T06:19:19+00:00

This problem has been driving me mad. Here’s the general gist: I have two

  • 0

This problem has been driving me mad. Here’s the general gist:

I have two projects in a solution: the first is an F# console application and the second is a C# library with a C#+XAML class called DisplayWindow inheriting from the WPF Window. DisplayWindow has a method public void SetMessage(string s) {...} that makes the window display the text passed to it in big shiny letters that will probably also flash and spin arround and do everything else WPF is good at.

The problem is: From my F# program I need to make a function let openAWindow text = ??? so that it will open a new DisplayWindow asynchronously every time its called with the text. What is the best way to do this? Using async {} or System.Threading.Thread? Thanks for the help 🙂

Edit: I found this blog post http://deanchalk.com/2010/10/08/f-interacting-with-wpf-dispatcher-via-f-interactive-window/ that works but can sometimes (?) cause an ArgumentException with the error text “An entry with the same key already exists.” so I have no idea whats going on there 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:19:19+00:00Added an answer on May 28, 2026 at 6:19 am

    I did this for our F# for Visualization library and then described the technique I used in my book Visual F# 2010 for Technical Computing.

    Firstly, I wrote a lazy thunk that initializes WPF (including an STA UI thread and Application) when its evaluation is forced:

    > 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>
    

    Then I wrote a spawn function that dispatches the application of a function f to an argument x such that it is run on the UI thread:

    > 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
    

    Now it is just a case of invoking your openAWindow function on the UI thread with:

    let openAWindow text =
      DisplayWindow().SetMessage text
    
    spawn openAWindow text
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem which has been driving me mad for days - I've
This problem has been kicking my butt for a few days now. I have
This has been driving me mad someone help coz i don't seem to see
This has been driving me nuts all day. I've seen this problem crop up
This has been driving me nuts for a week now. I have a class
This has been driving me nuts all day. I have a weird bug that
This problem has been bugging me for a while. I have to load a
This problem has been driving me nuts all day and there has to be
So this has just been driving me nuts! I have looked through tons of
I have a javascript function that has been driving me nuts. This is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.