Click here to Skip to main content
12,626,216 members (34,055 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
Trying to add an event handler its actually a switch to my program.(hope to add 2)
But its crashing runs like 3 seconds stops.
seems to crash around this point "if ((System.DateTime.Now.Ticks - lastDebounceTime) > debounceDelay)"

please help

namespace Hydro
{
    public class Program
    {
        public const int SecondMs = 1000;
        public const int MinuteMs = 60 * SecondMs;
        public const int HourMs = 60 * MinuteMs;
        public const int DayMs = 24 * HourMs;
        public const int WeekMs = 7 * DayMs;
 
        static bool method_state_6, method_state_7;
        static long lastDebounceTime = DateTime.Now.Ticks;
        static long debounceDelay = 100000;   //adjust as necessary
        
        
        static InputPort phcontroller = new InputPort(Pins.GPIO_PIN_D0, false, Port.ResistorMode.Disabled);
        static InputPort nutcontroller = new InputPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.Disabled);
        static OutputPort ph = new OutputPort(Pins.GPIO_PIN_D2, true);
        static OutputPort b = new OutputPort(Pins.GPIO_PIN_D3, true);
 
        static OutputPort a = new OutputPort(Pins.GPIO_PIN_D4, true);
        static OutputPort drain = new OutputPort(Pins.GPIO_PIN_D5, true);
        static OutputPort solenoid = new OutputPort(Pins.GPIO_PIN_D6, true);
        static OutputPort heater = new OutputPort(Pins.GPIO_PIN_D7, true);
        
        static OutputPort led = new OutputPort(Pins.GPIO_PIN_D11, true);
 

        
        public static void Main()
        {
		InterruptPort input = new InterruptPort(Pins.GPIO_PIN_D10, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
        	input.OnInterrupt += new NativeEventHandler(input_OnInterrupt);
	}
 
        static void input_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            if ((System.DateTime.Now.Ticks - lastDebounceTime) > debounceDelay)
            {
                lastDebounceTime = DateTime.Now.Ticks;
                // do stuff
            }
            {
 
                try
                {
                    Thread led_proc = new Thread(new ThreadStart(turn_led));
                    led_proc.Start();
                    while (true)
                    {
 
                        Method_1();
                        call2_5();
                        call6_8();
                        Method_9();
                        Thread.Sleep(10000);
Posted 6-Jan-13 11:47am
ve3tru219
Comments
   
What does it mean "around this point". You need to start with finding exact like where an expression is throw.
Generally, software developers don't say "crash".
—SA
jibesh 7-Jan-13 3:48am
   
Check the possibility of Christian Graus solution. that can also be a reason for your error. Or post the exact line where you are having trouble.
ve3tru 7-Jan-13 6:09am
   
"What does it mean "around this point"
Well on debug, it starts then it stops after like 3 seconds. Its like the whole program is finished. No errors no expression is throw or problems, and no more debug, so its difficult to gauge the exact point. The too many thread thing, is probable. From what I understand, is others have run up to 50 without a problem, it just gets real slow.(Total threads might be high but I'm only running like 3 same time) What I was told, is that in theory, you can have as many threads as you want, but it will slow it down to an unusable speed,I'm not having that problem.
I have tried many versions of this code, they all fail.I was thinking opening a new thread and use a while loop instead of the event handler but some how I think that's just more resource hungry.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Might it be crashing because it just creates more and more threads until it's run out of the ability to do so ? Each interrupt creates a thread, which will run forever.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

I think I solved it, it had to do with creating even more threads well at least ones
in a specific order of things.
Thanks
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161205.3 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100