[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 63
  • Last Modified:

c# if statement weird reaction

In a window form, I have a very simple "if" statement triggered by the state of a flag.

If the flag value is "true", a message box is supposed to be displayed only one time because it triggers a flag change to "false".

But, unexpectingly, instead of once, the messagebox is triggered 10 or 12 times.

I cannot understand why.

Any idea ??

bool signal = true;


while (imudata.TryDequeue(out  sensorData))
                        ChartFsr.Series["Heel"].Points.Add(new DataPoint(sensorData.AcquisitionTime, sensorData.HeelForce));
                        if (signal = true && sensorData.HeelForce > 1)
                        {
                            signal = false;
                            MessageBox.Show(signal.ToString());
                            break;
                        }    
                    }
                }

Open in new window

0
Paulagier
Asked:
Paulagier
1 Solution
 
Dustin SaundersDirector of OperationsCommented:
Your loop is setting signal to true, so it keeps looping.
if (signal = true && sensorData.HeelForce > 1)

Open in new window


Try:
if (signal == true && sensorData.HeelForce > 1)

Open in new window

0
 
p_davisCommented:
or just

if(signal && sensorData.HeelForce > 1)


also your while doesn't have {} but appears that it would need it. is signal a local member of a method or is it a class member?
1
 
PaulagierAuthor Commented:
Oops !!
Thank you
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now