I am trying to handle the button pressure.
I want to log the time when i press the button on Netduino plus but C# reports the following output message after i launch the app.
#### Exception System.OutOfMemoryException - CLR_E_OUT_OF_MEMORY (1) ####
#### Message:
#### System.Delegate::Combine [IP: 0000] ####
#### Microsoft.SPOT.Hardware.NativeEventDispatcher::add_OnInterrupt [IP: 0014] ####
#### NetduinoPlusApplication1.Program::Main [IP: 004a] ####
Uncaught exception
the code of my application is the following:
using System; using System.Net; using System.IO; using System.Net.Sockets; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.NetduinoPlus; namespace NetduinoPlusApplication1 { public class Program { public static void Main() { DirectoryInfo usd = new DirectoryInfo(@"\SD\"); InterruptPort button = new InterruptPort(Pins.GPIO_PIN_D8, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLevelLow); if (usd.Exists) { usd.Create(); usd.CreateSubdirectory(@"\SD\Prova\"); FileStream fstr = new FileStream(@"\SD\Prova\prova.dat", FileMode.Create); fstr.Flush(); fstr.Close(); while (true) { button.OnInterrupt += new NativeEventHandler(button_OnInterrupt); button.ClearInterrupt(); } //close while }//close if } //close Main static void button_OnInterrupt(uint port, uint state, DateTime time) { OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); int ltime = 50000; StreamWriter fstr1 = new StreamWriter(@"\SD\Prova\prova.dat", true); if (state == 0) { fstr1.WriteLine(System.DateTime.Now.ToString()); fstr1.Flush(); fstr1.Close(); led.Write(true); Thread.Sleep(ltime); led.Write(false); //Thread.Sleep(ltime); }; } } }
Could someone explain me something about the exception not handled and what generate the exception?
Thank you!
Rgds, Daniele.