Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BinaryReader and Stream performance on WP7

The question...

If you must have a BinaryReader opend to a file, is there a more performant way to do it than opening a Stream to a Resource?

 System.IO.Stream myFileStream = Application.GetResourceStream(new Uri @"/MyApp;component/sdb.data", UriKind.Relative)).Stream;
 BinaryReader binaryReader = new BinaryReader(myFileStream);

All the rest...

I am using the Sterling Database (codeplex) for a WP7 app. The app is required to ship with a large db already inside the assembly. Currently, I am attempting a Restore() with Sterling to create a database from a file that holds a previously saved ( Backup() ). Currently, I am taking the backup file and setting it as a 'Resource' in the app, as shown above. The Sterling dtabase engine requires a BinaryReader to load the data via a Restore(). Currently, the restore just takes too long. I have a discussion started in the Sterling Discussions, but posted here on Stack just to see if I could do better than a stream to a resource.

like image 740
Roger Avatar asked Dec 06 '25 04:12

Roger


1 Answers

It looks as though you are embedding your database as a resource - have you tried setting the Build Action property on the file to Content, and then loading it like this:

System.IO.Stream myFileStream = Application.GetResourceStream(new Uri(@"/component/sdb.data", UriKind.Relative)).Stream;

Although I've not tried it myself, using Content over Resource apparently has performance implications for images, and I assume, for other binary files: http://www.windowsphonegeek.com/tips/wp7-working-with-images-content-vs-resource-build-action

like image 56
Damian Avatar answered Dec 07 '25 18:12

Damian