How are DumpLive results for a long process?

I tried Observable.Create

waits for completion before showing any results. Possibly because the example I'm trying to follow is realtime value change, not live collection change.

and

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

I cannot use because it .DumpLive()

does not apply to ObservableCollection

.

+3


source to share


1 answer


Short answer : use LINQPad DumpContainer

:

var dc = new DumpContainer().Dump();

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

      

Long answer : DumpContainer

Writes to the standard LINQPad HTML results window, so you can see the value change in place when the main thread is blocked, whereas the call DumpLive

to IObservable uses WPF to render updates, so the main thread must stay unblocked to see updates as they happen ...



Alternatively, you can reset the 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);
}

      

As is the case with DumpLive

, you must be careful not to block the main thread. If you replaced await Task.Delay

with Thread.Sleep

, you would block the UI thread and nothing appeared until the end.

+2


source







All Articles