SDHC Reload Error on G120

I have an error when I try to reload the SD card (SDHC 4G Kingston) on G120 with Firmware 4.3.7.10. The first time when the application starts the SD card load OK, but if you remove it and insert it again,it shows an error and not files are found. Here I put a debug print of two cases:

**** First Load *******

[em]Insert event fired; SD card mount is finished.
File Sistem: FAT
ID: 0
Name: SD
Root: \SD
Serial Number: 0
Total Size: 4027318272
Free Space: 4026925056
File Sistem Flags: 0000
Device Flags: 0000
Load Device Config
Configuration File Found[/em]

***** Reload ******

[em]Insert event fired; SD card mount is finished.
File Sistem: FAT
ID: 0
Name: SD
Root: \SD
Serial Number: 0
Total Size: 4027318272
Free Space: 449183744
File Sistem Flags: 0000
Device Flags: 0000
Load Device Config
Configuration File NOT Found[/em]

As you can see on the first load the free space is 4026925056, but in the reload the free space is 449183744.

Can anyone help me??

Thanks

it would help to show code.

Here are the parts of the code that manage the SD Card on the Application:



        //Global Objects for SDCard
        private static SDCard SD = null;
        private static InputPort sdCardDetect;
        private static ManualResetEvent sdEvt = new ManualResetEvent(false);
        private static string rootDirectory = string.Empty;


        public static void Main()
        {
            RemovableMedia.Insert += new InsertEventHandler(RemovableMedia_Insert);
            RemovableMedia.Eject += new EjectEventHandler(RemovableMedia_Eject);
            sdCardDetect = new InputPort(G120.P1_8, false, Port.ResistorMode.PullUp);
            new Thread(SDMountThread).Start();
        }

        private static void RemovableMedia_Eject(object sender, MediaEventArgs e)
        {
            Debug.Print("SD card unmounted, eject event fired");
            sdEvt.Reset();
            SD.Dispose();
            SD = null;
            rootDirectory = string.Empty;          
        }

        private static void RemovableMedia_Insert(object sender, MediaEventArgs e)
        {
            Debug.Print("Insert event fired; SD card mount is finished.");.
            try
            {
                if (!e.Volume.IsFormatted)
                {
                    Debug.Print("SD card is not formatted.");
                    SD.Unmount();
                }
                else
                {
                    VolumeInfo Volume =  VolumeInfo.GetVolumes()[0];
                    Debug.Print("File Sistem: " + Volume.FileSystem);
                    Debug.Print("ID: " + Volume.VolumeID.ToString());
                    Debug.Print("Name: " + Volume.Name);
                    Debug.Print("Root: " + Volume.RootDirectory);
                    Debug.Print("Serial Number: " + Volume.SerialNumber.ToString());
                    Debug.Print("Total Size: " + Volume.TotalSize.ToString());
                    Debug.Print("Free Space: " + Volume.TotalFreeSpace.ToString());
                    Debug.Print("File Sistem Flags: " + Volume.FileSystemFlags.ToString("X4"));
                    Debug.Print("Device Flags: " + Volume.DeviceFlags.ToString("X4"));
                    rootDirectory = Volume.RootDirectory;
                    sdEvt.Set(); // proceed with other processing
                    Thread Hilo = new Thread(LoadConfigThread);
                    Hilo.Priority = ThreadPriority.Highest;
                    Hilo.Start();
                }
            }
            catch
            {
                SD.Unmount();
            }
        }

        private static void SDMountThread()
        {
            const int POLL_TIME = 500; // check every 500 millisecond
            bool sdExists;
            bool sdLoaded = false;
            while (true)
            {
                try
                {
                    sdExists = !sdCardDetect.Read();

                    // make sure it is fully inserted and stable
                    if (sdExists)
                    {
                        Thread.Sleep(POLL_TIME);
                        sdExists = !sdCardDetect.Read();
                    }

                    if (sdExists && SD == null)
                    {
                        Debug.Print("SD Card Inserted");
                        SD = new SDCard();
                        SD.Mount();
                        if (!sdLoaded)
                        {
                            // Fire SD Card Inserted Event of the Application
                            sdLoaded = true;
                        }
                    }
                    else if (!sdExists && SD != null)
                    {
                        Debug.Print("SD Card Removed");
                        SD.Unmount();
                        if (!sdExists)
                        {
                            if (sdLoaded)
                            {
                                sdLoaded = false;
                                // Fire SD Card Removed Event of the Application
                            }
                        }
                    }
                }
                catch
                {
                    if (SD != null)
                    {
                        sdEvt.Reset();
                        SD.Dispose();
                        SD = null;
                    }
                }
                Thread.Sleep(POLL_TIME);
            }
        }


@ DYDEX-HS - It looks like you call Unmount after you physically remove the SD card. Does the issue persist if you unmount before physically removing it?

In the posted code the Main() method is being exited. Could this be an issue?

@ John - That’s right, but how can I know when it will be removed?? In a standar application the idea is that it can support that anytime. But the program works perfect with SD Cards of 2G and 1G, the error is present only in SDHC Cards.

@ DYDEX-HS - Similar to the Windows option of Safely Remove, possibly a button next to the SD card. Adding that mechanism to test will at least narrow down the issue.