1

I've seen a lot of old examples in C# for long-running tasks using background worker etc- and am relatively new to F#.

I would like to set up some code in an F# project that runs for a while and reports progress back to a C# WPF progress bar.

I can see over time there are several ways to do it but I am having a bit of trouble finding out which methods are obsolete. Background worker , passing progress as a parameter when starting the task, binding using MVVM .

let DoSomething(progress: IProgress<int> ) = 
        for i in [1..100] do
            Thread.Sleep(100);
            progress.Report(i);
Martin Thompson
  • 3,415
  • 10
  • 38
  • 62
  • I think this depends somewhat on what do you want to do with the progress updates. Are they passed to just one place? Are these global things someone might want to subscribe for? Or are they just local updates consumed by single consumer? – Tomas Petricek Aug 01 '22 at 23:01
  • Thanks for your fast reply - that made me think a bit. I guess to start with we would want it just on 1 WPF app - so that running the task is seen in a progress bar and doesn't lock up the UI. We only need to see the progress. Maybe later I could make it report globally - I have done something like that in the past many years ago using signalR – Martin Thompson Aug 01 '22 at 23:05
  • https://stackoverflow.com/questions/62516174/f-making-the-result-of-an-async-workflow-available-to-be-displayed-by-the-ui-th – Jim Foye Aug 01 '22 at 23:39
  • https://stackoverflow.com/questions/70208381/updating-progressbar-value-in-fsxaml-and-elmishwpf – Bent Tranberg Aug 02 '22 at 05:59
  • That question and answer I linked to is a bit lengthy, and you might want to just skip it to get toing fast. So do this instead. At the start of the answer there's a link to my demo project on GitHub. Look at the two DemoAsync projects in the solution. And this uses Elmish.WPF, mixing XAML in C# and code in F#. – Bent Tranberg Aug 02 '22 at 06:03

0 Answers0