SD Card file write takes forever to Close or Flush

Hi, i’m playing with my SD Card module and having problem writing data to the card.

It takes forever to flush and I can’t seems to get the text file written.

Here’s my code


            sdCard.MountSDCard();
            sdCard.SDCardMounted += sdCard_SDCardMounted;
            sdCard.SDCardUnmounted += sdCard_SDCardUnmounted;

            VolumeInfo vi = sdCard.GetStorageDevice().Volume;
            Debug.Print(vi.Name);
            Debug.Print(vi.IsFormatted.ToString());
            Debug.Print(vi.FileSystem);
            Debug.Print(vi.TotalFreeSpace.ToString());

            string root = sdCard.GetStorageDevice().RootDirectory;
            Debug.Print("Root: " + root);


            var rootDirectory = sdCard.GetStorageDevice().RootDirectory;
            var textFile = new StreamWriter(rootDirectory + @ "\hello.txt");
            textFile.WriteLine("Hello SD card. " + DateTime.UtcNow.ToString());
            //textFile.Flush();
            textFile.Close();

            sdCard.UnmountSDCard();

Did i missed something obvious. I’m using FEZRaptor. NETMF 4.2

Hi,
try to call a method like this after the command: textFile.close();

 
textFile.close();
FinalizeVolumes();
Thread.Sleep(100);

private void FinalizeVolumes()
        {
            VolumeInfo[] vi = VolumeInfo.GetVolumes();
            for (int i = 0; i < vi.Length; i++)
                vi[i].FlushAll();
        }
 
1 Like

@ RoSchmi, it works. Thanks.

NOTE: Notice the SD card that come with the purchase of the SD Card Module is kinda slow. It works way better after I replace with the Kingston class 4 SD Card. Not sure if it’s just my case of others are experiencing the same.

You’re welcome.
What do you mean with slow? What is your datarate?

I need to copy these code
:smiley:

Too much honor, it’s not from me:

https://netmf.codeplex.com/workitem/2149