While removing a USB key from the USB host an exception is launched that stop my code:
[quote] #### Exception System.ArgumentOutOfRangeException - CLR_E_OUT_OF_RANGE (4) ####
#### Message:
#### System.Collections.ArrayList::get_Item [IP: 0000] ####
#### System.IO.FileSystemManager::ForceRemoveNameSpace [IP: 0026] ####
#### Microsoft.SPOT.IO.RemovableMedia::MessageHandler [IP: 005c] ####[/quote]
Here’s the code for the USBH class:
using System;
using System.IO;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using GHIElectronics.NETMF.IO;
using GHIElectronics.NETMF.USBHost;
namespace USU
{
public class USBH
{
// Hold a static reference in case the GC kicks in and disposes it
// automatically, note that we only support one in this example!
private static PersistentStorage USBps;
public bool is_cle_present = false;
public USBH()
{
// Subscribe to USB events
USBHostController.DeviceConnectedEvent += USB_connect_device;
USBHostController.DeviceDisconnectedEvent += USB_disconnect_device;
}
public void USB_connect_device(USBH_Device device)
{
if(device.TYPE == USBH_DeviceType.MassStorage)
{
Debug.Print("USB Mass Storage detected...");
USBps = new PersistentStorage(device);
USBps.MountFileSystem();
is_cle_present = true;
}
}
public void USB_disconnect_device(USBH_Device device)
{
is_cle_present = false;
Debug.Print("USB MASS Storage is ejected.");
USBps.UnmountFileSystem();
}
}
}
Does anyone know how to solve that?