Go Down

Topic: problem using lock statement in c# (Read 854 times) previous topic - next topic

Code: [Select]
  //create serial data
                BeginInvoke((Action)(()=>
                    {
                lock (measures)
                {
                    for (int i = 0; i < measures.Count; i++)
                    {
                        if (measures.Count >= 0.0 && measures.Count<=0.5)
                        {
                            double x = myCurveOne.Points.Count;
                            double y = measures[i];
                            myCurveOne.AddPoint(x, y);
                            myCurveOne.Line.Color = Color.Green;
                        }
                        else if (measures.Count>0.5 &&measures.Count<=0.6)
                        {
                            double x = myCurveTwo.Points.Count;
                            double y = measures[i];
                            myCurveTwo.AddPoint(x, y);
                            myCurveTwo.Line.Color = Color.Yellow;
                        }
                        else if (measures.Count > 0.6 && measures.Count <=0.7)
                        {
                            double x = myCurveThree.Points.Count;
                            double y = measures[i];
                            myCurveThree.AddPoint(x, y);
                            myCurveThree.Line.Color = Color.Red;
                        }
                        else
                            return;
                    }


can i use this multiple if-else statement inside the lock block statements.?

PaulS

#1
Dec 30, 2012, 05:16 pm Last Edit: Dec 30, 2012, 05:18 pm by PaulS Reason: 1
Quote
can i use this multiple if-else statement inside the lock block statements.?

You have my permission. I don't see that this has anything to do with an Arduino.

I don't know what measures is an instance of, but I am not aware of any class in C# that has a Count property that is anything other than an integer value.

robtillaart

think you mean this
Code: [Select]

BeginInvoke((Action)(()=>
                    {
                lock (measures)
                {
                    for (int i = 0; i < measures.Count; i++)
                    {
                        if (measures[i] <= 0 )
                        {
                          return;
                        }
                        else if (measures[i] <= 0.5)
                        {
                            double x = myCurveOne.Points.Count;
                            double y = measures[i];
                            myCurveOne.AddPoint(x, y);
                            myCurveOne.Line.Color = Color.Green;
                        }
                        else if (measures[i] <= 0.6)
                        {
                            double x = myCurveTwo.Points.Count;
                            double y = measures[i];
                            myCurveTwo.AddPoint(x, y);
                            myCurveTwo.Line.Color = Color.Yellow;
                        }
                        else if (measures[i] <= 0.7)
                        {
                            double x = myCurveThree.Points.Count;
                            double y = measures[i];
                            myCurveThree.AddPoint(x, y);
                            myCurveThree.Line.Color = Color.Red;
                        }
                        else  // measures[i] > 0.7
                            return;
                    }
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart,

i am thinking like that..but for the value measure 0-5 im referring to the first if-else block statement.. n so on..does the code works on the condition that i have set on my original coding?

thanks...

robtillaart

Quote
does the code works on the condition that i have set on my original coding?

Don't know what you mean exactly, I have tried to rewrite the code to what you probably meant it should do.

in your code you use measure.Count  not   measure  

I kept the conditions in the code semantically equal.

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy