Pages: [1]   Go Down
Author Topic: problem using lock statement in c#  (Read 703 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  //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.?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: December 30, 2012, 11:18:15 am by PaulS » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

think you mean this
Code:
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;
                    }
Logged

Rob Tillaart

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

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Rob Tillaart

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

Pages: [1]   Go Up
Jump to: