Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 Try

The 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?

Posted

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.

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...