Solved

c# if statement weird reaction

Posted on 2016-11-22
3
54 Views
Last Modified: 2016-11-22
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
Comment
Question by:Paulagier
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 13

Accepted Solution

by:
Dustin Saunders earned 500 total points
ID: 41897653
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
 
LVL 22

Expert Comment

by:p_davis
ID: 41897666
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
 

Author Closing Comment

by:Paulagier
ID: 41897814
Oops !!
Thank you
0

Featured Post

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question