Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

simple code need help


  • Please log in to reply
44 replies to this topic

#21 perkunas

perkunas

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts

Posted 01 April 2012 - 01:32 AM

ok as sad as this is, it should be complete or for that matter completely wrong because I wrote it. but that's basically it. I added 2 more, Thread_5(),blinks on off should only start after the 1st 1-4 are done (i hope it resets ie stops on start up again. Thread_6() is suppose to loop another 14 days. ///still getting errors. using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino; namespace controller { 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; public static void Main() { OutputPort ph = new OutputPort(Pins.GPIO_PIN_D2, true); OutputPort b = new OutputPort(Pins.GPIO_PIN_D3, true); OutputPort a = new OutputPort(Pins.GPIO_PIN_D4, true); OutputPort drain = new OutputPort(Pins.GPIO_PIN_D5, true); OutputPort solenoid = new OutputPort(Pins.GPIO_PIN_D6, true); OutputPort heater = new OutputPort(Pins.GPIO_PIN_D7, true); OutputPort controller = new OutputPort(Pins.GPIO_PIN_D8, true); drain.Write(false); Thread.Sleep(16 * MinuteMs); drain.Write(true); Thread tid_1 = new Thread(new ThreadStart(Thread_1)); Thread tid_2 = new Thread(new ThreadStart(Thread_2)); Thread tid_3 = new Thread(new ThreadStart(Thread_3)); Thread tid_4 = new Thread(new ThreadStart(Thread_4)); Thread tid_5 = new Thread(new ThreadStart(Thread_5)); Thread tid_6 = new Thread(new ThreadStart(Thread_4)); tid_1.Start(); tid_2.Start(); tid_3.Start(); tid_4.Start(); tid_1.Join(); tid_2.Join(); tid_3.Join(); tid_4.Join(); tid_5.Start(); tid_6.Start(); tid_5.Join(); tid_6.Join(); } public static void Thread_1() { solenoid.Write(false); Thread.Sleep(16 * MinuteMs); solenoid.Write(true); } public static void Thread_2() { a.Write(false); Thread.Sleep(3 * SecondMs); a.Write(true); } public static void Thread_3() { b.Write(false); Thread.Sleep(6 * MinuteMs + 3 * SecondMs); b.Write(true); } public static void Thread_4() { ph.Write(false); Thread.Sleep(11 * MinuteMs + 7 * SecondMs); ph.Write(true); } public static void Thread_5() { while (true) controller.Write(false); Thread.Sleep(1 * SecondMs); controller.Write(true); Thread.Sleep(10 * MinuteMs); } public static void Thread_6() { for (int i = 0; i < 14; i++) Thread.Sleep(1 * DayMs); solenoid.Write(false); Thread.Sleep(20 * SecondMs); solenoid.Write(true); { } } } }

#22 Geancarlo2

Geancarlo2

    Advanced Member

  • Members
  • PipPipPip
  • 70 posts

Posted 01 April 2012 - 01:50 AM

You have declared your variables inside Main() so they only exist in that scope. Declare them like below after your consts:

static OutputPort blahblah=new OutputPort(etcetc);

you also forgot {} in Thread_5 and Thread_6

#23 perkunas

perkunas

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts

Posted 01 April 2012 - 02:46 AM

ok il fix it tnx

#24 perkunas

perkunas

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts

Posted 01 April 2012 - 02:55 AM

Still getting namespace definition, or end of file expected not sure 5 and 6 is right needs to start only after 1-4 is done maybe i need to move the start time? using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino; namespace controller { 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 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 controller = new OutputPort(Pins.GPIO_PIN_D8, true); public static void Main() { drain.Write(false); Thread.Sleep(16 * MinuteMs); drain.Write(true); Thread tid_1 = new Thread(new ThreadStart(Thread_1)); Thread tid_2 = new Thread(new ThreadStart(Thread_2)); Thread tid_3 = new Thread(new ThreadStart(Thread_3)); Thread tid_4 = new Thread(new ThreadStart(Thread_4)); Thread tid_5 = new Thread(new ThreadStart(Thread_5)); Thread tid_6 = new Thread(new ThreadStart(Thread_4)); tid_1.Start(); tid_2.Start(); tid_3.Start(); tid_4.Start(); tid_1.Join(); tid_2.Join(); tid_3.Join(); tid_4.Join(); tid_5.Start(); tid_6.Start(); tid_5.Join(); tid_6.Join(); } public static void Thread_1() { solenoid.Write(false); Thread.Sleep(16 * MinuteMs); solenoid.Write(true); } public static void Thread_2() { a.Write(false); Thread.Sleep(3 * SecondMs); a.Write(true); } public static void Thread_3() { b.Write(false); Thread.Sleep(6 * MinuteMs + 3 * SecondMs); b.Write(true); } public static void Thread_4() { ph.Write(false); Thread.Sleep(11 * MinuteMs + 7 * SecondMs); ph.Write(true); } public static void Thread_5() { while (true) controller.Write(false); Thread.Sleep(1 * SecondMs); controller.Write(true); Thread.Sleep(10 * MinuteMs); } public static void Thread_6() { for (int i = 0; i < 14; i++) Thread.Sleep(1 * DayMs); solenoid.Write(false); Thread.Sleep(20 * SecondMs); solenoid.Write(true); } } } } }

#25 Geancarlo2

Geancarlo2

    Advanced Member

  • Members
  • PipPipPip
  • 70 posts

Posted 01 April 2012 - 02:56 AM

This \/ is what I meant and you are missing the {} on your loops inside thread_5 and 6. In terms of syntax I think there's nothing else to be fixed..
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 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 controller = new OutputPort(Pins.GPIO_PIN_D8, true);



public static void Main()
{
drain.Write(false);
Thread.Sleep(16 * MinuteMs);
drain.Write(true);

Thread tid_1 = new Thread(new ThreadStart(Thread_1));
Thread tid_2 = new Thread(new ThreadStart(Thread_2));
Thread tid_3 = new Thread(new ThreadStart(Thread_3));
Thread tid_4 = new Thread(new ThreadStart(Thread_4));
Thread tid_5 = new Thread(new ThreadStart(Thread_5));
Thread tid_6 = new Thread(new ThreadStart(Thread_4));
.
.
.


#26 perkunas

perkunas

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts

Posted 01 April 2012 - 03:17 AM

so close now fixed a couple }} at the bottom but now down to one error in thread 5 Thread.Sleep(1 * SecondMs); highlighted that's suppose to loop on off until the whole thing loops ///unreachable code detected. what ever that means.

#27 Geancarlo2

Geancarlo2

    Advanced Member

  • Members
  • PipPipPip
  • 70 posts

Posted 01 April 2012 - 03:29 AM

That line was pointed as unreachable because you probably forgot the brackets, so your while true loop would repeat "controller.Write(false);" indefinitely. :D


public static void Thread_5()
{
while (true)
{
controller.Write(false);
Thread.Sleep(1 * SecondMs);
controller.Write(true);
Thread.Sleep(10 * MinuteMs);
}
}
public static void Thread_6()
{
for (int i = 0; i < 14; i++)
{
Thread.Sleep(1 * DayMs);
solenoid.Write(false);
Thread.Sleep(20 * SecondMs);
solenoid.Write(true);
}

}

#28 perkunas

perkunas

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts

Posted 01 April 2012 - 03:49 AM

yahoo your a genius it compiles, and I'm done I hope. I have some concerns, will 1-4 thread fire 1st then the 5-6 thread then 7 like its suppose to and not all same time. and 6 thread is suppose to loop 14 times. Reason I ask all this, is because this is my 1st C# program and this stuff just seems a little too easy, well it was easy with a lot of help. Tnx using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino; namespace controller { 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 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 controller = new OutputPort(Pins.GPIO_PIN_D8, true); public static void Main() { drain.Write(false); Thread.Sleep(16 * MinuteMs); drain.Write(true); Thread tid_1 = new Thread(new ThreadStart(Thread_1)); Thread tid_2 = new Thread(new ThreadStart(Thread_2)); Thread tid_3 = new Thread(new ThreadStart(Thread_3)); Thread tid_4 = new Thread(new ThreadStart(Thread_4)); Thread tid_5 = new Thread(new ThreadStart(Thread_5)); Thread tid_6 = new Thread(new ThreadStart(Thread_6)); Thread tid_7 = new Thread(new ThreadStart(Thread_7)); tid_1.Start(); tid_2.Start(); tid_3.Start(); tid_4.Start(); tid_1.Join(); tid_2.Join(); tid_3.Join(); tid_4.Join(); tid_5.Start(); tid_6.Start(); tid_5.Join(); tid_6.Join(); tid_7.Start(); } public static void Thread_1() { solenoid.Write(false); Thread.Sleep(16 * MinuteMs); solenoid.Write(true); } public static void Thread_2() { a.Write(false); Thread.Sleep(3 * SecondMs); a.Write(true); } public static void Thread_3() { b.Write(false); Thread.Sleep(6 * MinuteMs + 3 * SecondMs); b.Write(true); } public static void Thread_4() { ph.Write(false); Thread.Sleep(11 * MinuteMs + 7 * SecondMs); ph.Write(true); } public static void Thread_5() { while (true) { controller.Write(false); Thread.Sleep(1 * SecondMs); controller.Write(true); Thread.Sleep(10 * MinuteMs); } } public static void Thread_6() { for (int i = 0; i < 14; i++) heater.Write(true); Thread.Sleep(1 * DayMs); solenoid.Write(false); Thread.Sleep(20 * SecondMs); solenoid.Write(true); } public static void Thread_7() { drain.Write(false); Thread.Sleep(16 * MinuteMs); drain.Write(true); solenoid.Write(false); Thread.Sleep(16 * MinuteMs); solenoid.Write(true); Thread.Sleep(30 * MinuteMs); } } }

#29 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 01 April 2012 - 03:16 PM

Each thread will fire away instantly when you issue the tid_X.Start() statement.

#30 perkunas

perkunas

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts

Posted 01 April 2012 - 04:02 PM

crap...I was afraid of that, I was trying to check it with leds as a test that's just a lil too hard to do. thought it might go in order but no. 1-4 thread should fire 1st finish then the 5-6 fire finish, then 7 fire finish this one doesn't need to be as a thread its not multitasking but it was anyway, Finnish and loop. From what i read its not so simple. might have to combine them (ie.rewrire this)or put in a pause whatever that means. Also all kinds of memory issues, not sure how you know what its using. Cant say this is that complicated for those kind of problems but what do I know. tried moving the tid_.Start(); around, no luck getting errors, any hints??? I thought I had it, and was done oh well.

#31 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 01 April 2012 - 05:59 PM

As the program is written now, threads 1 to 4 will start simultaneously. Due to the four Join statements following that, the main program will wait until they're all finished before starting threads 5 and 6. Again, main program will wait until these two are also finished and then finally start thread 7. However, since you have an internal loop in Thread_5 meaning that the tid_5.Join() will block forever. Another problem is that the main program will exit before Thread_7 is finished since you run it as a thread. Instead you could simply call Thread_7 as a subroutine, this way the main program will not finish until Thread_7 is finished. Another way would be to add a tid_7.Join() as the last statement of your main program. Think of threads as small programs being able to execute on their own in parallel to anything else. I confess to still not being entirely sure of what you're trying to accomplish. Maybe you could explain in more detail and I could suggest a solution based on that.

#32 perkunas

perkunas

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts

Posted 01 April 2012 - 07:36 PM

Ill try to explain it the best I can 1) 1-4 run and wait till finished (Perfect) 2) 5-6 now run; 5 will loop on itself forever blinking on and off 6 will run loop on itself for 14 days only 3) after the 14 days 7 runs and the whole thing loops. starts over Sounds like not what I have, but its what I'm trying to do 7 really doesn't loop or multitask needs to run at the end b4 the final loop maybe your right all i need is simply call Thread_7 as a subroutine but it still needs to run after the 14day loop in 6 (Its going to be)x ie variable days. Ran some leds and I think your right on the money 5-6 are joined since 5 loops forever the thread 5&6 wont end that's useful to know for other projects too. Going to need something to tell 5 to stop after 6 is done. wow came up with an idea, why not a loop counter of some sort let 6 loop 14 times like its suppose to which can now can tell 5 to beak out of the loop. thanks for all the help and don't give up on me I'm almost there

#33 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 02 April 2012 - 08:08 AM

In that case, after you have fixed that bracket things, I think your main program could look something like this:
public static void Main()
        {
            // Note, this will block 16 minutes before
            // anything else will run
            drain.Write(false);
            Thread.Sleep(16 * MinuteMs);
            drain.Write(true);

            Thread tid_1 = new Thread(new ThreadStart(Thread_1));
            Thread tid_2 = new Thread(new ThreadStart(Thread_2));
            Thread tid_3 = new Thread(new ThreadStart(Thread_3));
            Thread tid_4 = new Thread(new ThreadStart(Thread_4));
            Thread tid_5 = new Thread(new ThreadStart(Thread_5));
            Thread tid_6 = new Thread(new ThreadStart(Thread_6));
            Thread tid_7 = new Thread(new ThreadStart(Thread_7));

            while (true)
            {
		// I'm not entirely sure this is the correct way to
		// restart the threads
                tid_1.Start();
                tid_2.Start();
                tid_3.Start();
                tid_4.Start();

                tid_1.Join();
                tid_2.Join();
                tid_3.Join();
                tid_4.Join();

                if (tid_5.ThreadState != ThreadState.Running)
                    tid_5.Start();

                tid_6.Start();
                tid_6.Join();

                tid_7.Start();
                tid_7.Join();
            }
        }


#34 perkunas

perkunas

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts

Posted 02 April 2012 - 11:09 AM

Looks like a well thought out plan but using the ... the while (true) { everything here loops forever so.... } //but I also have this that needs to run 1st on every loop // Note, this will block 16 minutes before // anything else will run drain.Write(false); Thread.Sleep(16 * MinuteMs); drain.Write(true); Its now outside the loop and in at the beginning meaning this will only run only once. It needs to be in the loop or am I wrong? maybe in or as a thread too Also the.... public static void Thread_5() { while (true) { controller.Write(false); Thread.Sleep(1 * SecondMs); controller.Write(true); Thread.Sleep(10 * MinuteMs); } This would loop forever, the idea was for it to loop continuously until the main loop starts over, so it resets itself ie turns off in the beginning before it reaches the // Note, this will block 16 minutes before // anything else will run drain.Write(false); Thread.Sleep(16 * MinuteMs); drain.Write(true); or am I wrong here? got to go to work, Ill have to get back to it a little later

#35 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 02 April 2012 - 03:59 PM

Ok, so run this as a thread at the beginning of the main loop:

            drain.Write(false);
            Thread.Sleep(16 * MinuteMs);
            drain.Write(true);

If it needs to run in parallel with the other threads, don't issue a Join() on it.

Also, make tid_5.Start() unconditional and add a tid_5.Abort() as the last statement in your main loop.

Things are getting a little messy but as soon as you get it working correctly, you can clean up the code.

#36 perkunas

perkunas

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts

Posted 02 April 2012 - 11:54 PM

ok this is wrong but I think more in line to what needs to be done I think 5 becomes 6 as I added a thread tid_6.Start() unconditional; //error for some reason 6 and 7 are joined, 6 loops forever, once 7 finishes I want 6 to stop.I cant put the tid_6.Abort()at the end of the main loop as it will end after thread 8 not 7 look at thread 7 maybe something like what I wrote there(I know its wrong..) its looping 14 times and if you tell it I'm now done 14 loops kill thread 6.Or move the tid_6.Abort() past the { close in 7 but I don't think that works using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino; namespace controller { 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 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 controller = new OutputPort(Pins.GPIO_PIN_D8, true); public static void Main() { Thread tid_1 = new Thread(new ThreadStart(Thread_1)); Thread tid_2 = new Thread(new ThreadStart(Thread_2)); Thread tid_3 = new Thread(new ThreadStart(Thread_3)); Thread tid_4 = new Thread(new ThreadStart(Thread_4)); Thread tid_5 = new Thread(new ThreadStart(Thread_5)); Thread tid_6 = new Thread(new ThreadStart(Thread_6)); Thread tid_7 = new Thread(new ThreadStart(Thread_7)); Thread tid_8 = new Thread(new ThreadStart(Thread_8)); tid_1.Start(); tid_2.Start(); tid_3.Start(); tid_4.Start(); tid_5.Start(); tid_2.Join(); tid_3.Join(); tid_4.Join(); tid_5.Join(); tid_6.Start() unconditional; tid_7.Start(); tid_6.Join(); tid_7.Join(); tid_8.Start(); } public static void Thread_1() { drain.Write(false); Thread.Sleep(16 * MinuteMs); drain.Write(true); } public static void Thread_2() { solenoid.Write(false); Thread.Sleep(16 * MinuteMs); solenoid.Write(true); } public static void Thread_3() { a.Write(false); Thread.Sleep(3 * SecondMs); a.Write(true); } public static void Thread_4() { b.Write(false); Thread.Sleep(6 * MinuteMs + 3 * SecondMs); b.Write(true); } public static void Thread_5() { ph.Write(false); Thread.Sleep(11 * MinuteMs + 7 * SecondMs); ph.Write(true); } public static void Thread_6() { while (true) { controller.Write(false); Thread.Sleep(1 * SecondMs); controller.Write(true); Thread.Sleep(10 * MinuteMs); } } public static void Thread_7() { for (int i = 0; i < 14; i++) heater.Write(true); Thread.Sleep(1 * DayMs); solenoid.Write(false); Thread.Sleep(20 * SecondMs); solenoid.Write(true); if i == 14 then tid_6.Abort() } public static void Thread_8() { drain.Write(false); Thread.Sleep(16 * MinuteMs); drain.Write(true); solenoid.Write(false); Thread.Sleep(16 * MinuteMs); solenoid.Write(true); Thread.Sleep(30 * MinuteMs); } } }

#37 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 03 April 2012 - 06:43 AM

This is syntactically wrong:
tid_6.Start() unconditional;
I meant for you to only remove the if-statement around it so it would become like so:
tid_6.Start();
I see that you now forgot to loop the main program. Also, main program will exit before thread 8 is finished so you probably need to Join that one too. You probably want to have your main program looking like this now:
public static void Main()
{
    Thread tid_1 = new Thread(new ThreadStart(Thread_1));
    Thread tid_2 = new Thread(new ThreadStart(Thread_2));
    Thread tid_3 = new Thread(new ThreadStart(Thread_3));
    Thread tid_4 = new Thread(new ThreadStart(Thread_4));
    Thread tid_5 = new Thread(new ThreadStart(Thread_5));
    Thread tid_6 = new Thread(new ThreadStart(Thread_6));
    Thread tid_7 = new Thread(new ThreadStart(Thread_7));
    Thread tid_8 = new Thread(new ThreadStart(Thread_8));

    while(true)  // added this
    {
        tid_1.Start();
 
        tid_2.Start();
        tid_3.Start();
        tid_4.Start();
        tid_5.Start();
 
        tid_2.Join();
        tid_3.Join();
        tid_4.Join();
        tid_5.Join();
 
        tid_6.Start();
        tid_7.Start();
 
        tid_6.Join();
        tid_7.Join();
        tid_6.Abort(); // added this
 
        tid_8.Start();
        tid_8.Join(); // added this
    }
}
Regarding thread 7, the "if i == 14" statement is meaningless as the variable "i" will always be 14 at this point plus it is not defined in that scope. I see you still haven't fixed the bracket thing of the loop so I'm not sure how it should work but I think this would probably work better for you:
public static void Thread_7()
{
     heater.Write(true);
     for (int i = 0; i < 14; i++)
     {
          solenoid.Write(true);
          Thread.Sleep(1 * DayMs);
          solenoid.Write(false);
          Thread.Sleep(20 * SecondMs); 
    }
    heater.Write(false); // added this
}
I feel you tend to change the desired functionality just a little in between some posts which makes it difficult for me to know what your goal is and thus to aid in achieving that. I think you have to decide once and for all exactly what you want to do and then stick with that. When you got that working, you can start making some adjustments (if needed) and evaluate their effect on the program.

Before proceeding with this project, I strongly think you should study some simpler examples to get a better understanding of the C# programming language syntax, how threads work and the general flow of control in an application. Please do this and then come back here if you still need to.

#38 perkunas

perkunas

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts

Posted 03 April 2012 - 11:56 PM

I want to thank you for everything it compiles and you have been very patient with me; even though I did change things along the way. But I have a final question. tid_8.Join(); you added this. This thread is on its own so does it need to be joined? If so tid_1.Start(); should have a tid_1.Join(); also. as that one is on its own once again many thanks { tid_1.Start(); tid_2.Start(); tid_3.Start(); tid_4.Start(); tid_5.Start(); tid_2.Join(); tid_3.Join(); tid_4.Join(); tid_5.Join(); tid_6.Start(); tid_7.Start(); tid_6.Join(); tid_7.Join(); tid_6.Abort(); // added this tid_8.Start(); tid_8.Join(); // added this

#39 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 04 April 2012 - 10:05 AM

Duplicate post, ignore this.

#40 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 04 April 2012 - 10:06 AM

Just happy to help!

Like you say, thread 8 should not be joined since it is to runs on its own. The same goes for thread 1.

Since thread 6 has an eternal loop inside it, you cannot join it, so to stop it (once thread 7 is finished), you'll have to abort it.

Also, you can't start a thread twice so because you're in a loop you'll have to start thread 8 only if it's not already running.

I think I made some mistake before, but I think this will get you closer to your goal:
tid_1.Start(); // this is outside the loop

while(true)
{
	tid_2.Start();
	tid_3.Start();
	tid_4.Start();
	tid_5.Start();

	tid_2.Join();
	tid_3.Join();
	tid_4.Join();
	tid_5.Join();

	tid_6.Start();

	tid_7.Start();
	tid_7.Join();

	tid_6.Abort();

  	if(tid_8.ThreadState != ThreadState.Running)
		tid_8.Start();
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.