Dump collections as each item is processed
Every so often, I would be running a long running query that yields many results. And every once in a while, when dumping the results, there is a failure because of some exception (e.g., OutOfMemoryException, NullReferenceException, etc.) and you never see any of the results because of that. The dump method only writes to the results until the entire collection has been processed and renders them all at once.
It would be nice if LINQPad would dump each item as the collection was being processed so in the event of a failure, we could see the results that have been processed so far.
Workarounds that I have used include looping over the collection dumping each item individually or writing to a file instead. Neither option is desirable.
When dumping each individual item, they aren't grouped together anymore so instead of having one collapsible collection, you have 10s to 100s of individual results which is harder to grok at. Writing to a file doesn't have all the nice formatting that LINQPad provides.
-
Piers Williams commented
The IObservable support is awesome, but I'm still surprised that Linqpad doesn't (appear to) implement the same progressive rendering for IEnumerables passed to the Dump() method.
You'd have to throttle the UI refresh rate, sure, but for long-running IEnumerables, progressive rendering would be a much nicer experience IMHO. And (hopefully) fairly easy to implement on top of the existing IObservable support.
-
Jeff Mercado commented
That'll work. Though I'd prefer if it was the default behavior of Dump() if possible.
-
Markus Jarderot commented
Using the current beta:
public static IList<T> Dump2<T>(this IEnumerable<T> items)
{
var collected = new List<T>();
var container = new DumpContainer();
container.Dump();
container.Content = collected;
foreach (var item in items)
{
collected.Add(item);
container.Refresh();
}
return collected;
}and then
Enumerable.Range(0, 10).Select(i =>
{
Thread.Sleep(1000);
return i;
}).Dump2(); -
This is supported in the latest beta if the collection implements IObservable
-
Jeff Mercado commented
To demonstrate, you would have to wait 10 seconds to see any results for this:
Enumerable.Range(0, 10).Select(i =>
{
Thread.Sleep(1000);
return i;
}).Dump();For this, you won't get any results at all, just the exception.
Enumerable.Range(0, 10).Select(i =>
{
Thread.Sleep(1000);
if (i > 8)
throw new Exception("No results for you");
return i;
}).Dump();