Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# ProgressBar with Deserialize()

I have a few large object graphs which I have serialised, and some of them take a few moments to deserialise.

At this stage, I'm quite happy with my little "Please Wait..." box which appears and then disappears at completion, but I was just toying with the idea of having some sort of progress bar in the event that deserialisation starts taking longer.

It doesn't seem like there's any way to get the progress of the built-in Deserialize() method for the BinaryFormatter object. I suspect that had such a feature been included, there would be some sort of asynchronous callback which would poll whenever a block of bytes was read from the stream.

Have any of you seen an implementation of ProgressBar-like behaviour with object serialisation/deserialisation?

like image 430
Ozzah Avatar asked Mar 20 '11 23:03

Ozzah


1 Answers

Stephen Toub discusses an approach to this problem in the .NET Matters column of the December 2006 MSDN Magazine.

He implements a wrapper around the stream which then allows intercepting of the Read method and raising a suitable event to signal progress.

like image 170
David Gardiner Avatar answered Oct 01 '22 22:10

David Gardiner