joe_pool_is Posted April 8, 2008 Posted April 8, 2008 We have been receiving a lot of high capacity flash drives with bad memory in the upper parts of the drive. For a 16 GB flash drive, most would probably never notice it, but once you do, the drive may become unreadable and all the data is gone! One way we have been testing the drives is by copying just under 16 GB of photos and MP3s to it, then deleting them back off. But I'm a Developer! I want to develop something to do this instead! I created a simple form with a start button. When the button is clicked, there is a simple loop inside a Try statement that writes data using a StreamWriter object:Dim writer As New StreamWriter("F:\\filler.dat") Try While (True) writer.Write("Red Rum! ") End While Catch ex As Exception Finally writer.Close() End TryThe theory was, once the flash drive runs out of memory space, an Exception would be thrown within the Try block and the Finally block would neatly close the file. The problem was, it ran for about 2 hours last night, and wasn't even up to 1-GB yet. Yuck! Is there a better, faster way to accomplish my objective? Quote Avoid Sears Home Improvement
techmanbd Posted April 8, 2008 Posted April 8, 2008 Yes it will take along time to do the way you do it. I know this as we do log files for our automated test for days and weeks. I would make a file around 300 to 500 megabytes, then "copy as" to the file until you reach close to 16 meg. Or using a photo that is high in bytes. Then "save as" Pic1, Pic2, etc,,,, The picture way would be better I think now that I think about it. Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
Leaders snarfblam Posted April 11, 2008 Leaders Posted April 11, 2008 If you use a filestream and just write large blocks from a large byte array it should go just about as fast as anything. For example, C# Code[HorizontalRule]magic hidden text[/HorizontalRule]FileStream fs = new FileStream("E:\\test.txt", FileMode.Create, FileAccess.Write); byte[] bigArray = new byte[1024 * 1024*4]; // 4 megs for(int i = 0; i < 256; i++) { // Write 1 gig ····fs.Write(bigArray, 0, 1024 * 1024 * 4); ····// Update progress bar, etc. ····Application.DoEvents(); } fs.Close();[HorizontalRule]Why are you quoting me?[/HorizontalRule] Copying large files should work just as well, though. Quote [sIGPIC]e[/sIGPIC]
joe_pool_is Posted April 12, 2008 Author Posted April 12, 2008 That would certainly work a lot faster! Hey, how do you specify C# code in the tag? Quote Avoid Sears Home Improvement
techmanbd Posted April 12, 2008 Posted April 12, 2008 use "cs" in the brackets instead of "vb". Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
Leaders snarfblam Posted April 14, 2008 Leaders Posted April 14, 2008 I probably should have noticed that you used VB and not C# in your posted code, and posted my example in VB. Sorry. Quote [sIGPIC]e[/sIGPIC]
joe_pool_is Posted April 14, 2008 Author Posted April 14, 2008 Oh, it's no biggie. I use both, but generally show my examples in VB so more people can read my code. I actually prefer C#. Quote Avoid Sears Home Improvement
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.