Solved

c# if statement weird reaction

Posted on 2016-11-22
3
27 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
Comment Utility
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
Comment Utility
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
Comment Utility
Oops !!
Thank you
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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

7 Experts available now in Live!

Get 1:1 Help Now