Search code examples
system.reactivelinqpad

How do I DumpLive results of a long running process?


I've tried Observable.Create

waits to finish before showing any results. Possibly because the example I'm trying to follow is a changing live value, not a changing live collection.

and

ObservableCollection<FileAnalysisResult> fileAnalysisResults = new ObservableCollection<FileAnalysisResult>();

I can't seem to apply because .DumpLive() isn't applicable to an ObservableCollection.


Solution

  • Short answer: use LINQPad's DumpContainer:

    var dc = new DumpContainer().Dump();
    
    for (int i = 0; i < 100; i++)
    {
        dc.Content = i;
        Thread.Sleep(100);
    }
    

    Long answer: DumpContainer writes to LINQPad's standard HTML results window, so you can see the value change in place while the main thread is blocked, whereas calling DumpLive on an IObservable uses a WPF control to render the updates, so the main thread must remain unblocked in order to see updates as they occur.

    It's also possible to dump a WPF or Windows Forms control and update it in place:

    var txt = new TextBox().Dump();
    for (int i = 0; i < 100; i++)
    {
        txt.Text = i.ToString();
        await Task.Delay(100);
    }
    

    Just as with DumpLive, you must be careful not to block the main thread. If you replaced await Task.Delay with Thread.Sleep, you'd block the UI thread and nothing would appear until the end.