Solved

c# if statement weird reaction

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now