Solved

c# if statement weird reaction

Posted on 2016-11-22
3
49 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 12

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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!
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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