Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7435933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:09:29+00:00 2026-05-29T10:09:29+00:00

I have an event inside my program in which there are values of tantheta

  • 0

I have an event inside my program in which there are values of tantheta keeps on changing on subsequent events fires.

The problem is that I have to check whether this value of tantheta holds within a certain range of 0.6 to 1.5 for a period of 3 seconds.

I tried some things with the timer but didn’t work out. Any suggestions?

EDIT–

DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();
//This event is fired automatically 32 times per second.
private void SomeEvemt(object sender, RoutedEventArgs e)
{
tantheta = ; tantheta gets a new value here through some calculation

timer.Tick += new EventHandler(timer_Tick);
timer.Interval = new TimeSpan(0, 0, 5);
timer.Start();
//if condition to check if tantheta is within range and do something

}

void timer_Tick(object sender, EventArgs e)
        {
            DispatcherTimer thisTimer = (DispatcherTimer)sender;
            textBox1.Text = thisTimer.Interval.ToString();
            thisTimer.Stop();
            return;
        }

I have to check if tantheta value remains within 0.6 to 1. for three seconds. I though timer would be a good approach since it would prevent my application from freezing during all these calculations because it goes to a separate thread. :-/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:09:31+00:00Added an answer on May 29, 2026 at 10:09 am

    A timer is useless because you will poll too many times and miss out on a change/change back.

    You will have to encapsulate the setting of the variable.
    This way you can respond to changes of the variable.

    class A
    {
        private double _tantheta; // add public getter
        private bool _checkBoundaries; // add public getter/setter
        public event EventHandler TanThetaWentOutOfBounds;
        public void SetTantheta(double newValue)
        {
            if(_checkBoundaries &&
                (newValue < 0.6 || newValue > 1.5))
            {
                var t = TanThetaWentOutOfBounds;
                if(t != null)
                {
                    t(this, EventArgs.Empty);
                }
            }
            else
            {
                _tantheta = newValue;  
            }
        }
    

    Now all you have to do is subscribe to the TanThetaWentOutOfBounds event of this class and set the CheckBoundaries to true or false.

    Note that this code does not fix any multi threading issues so you might have to add some locking depending on your use of the class.

    There are two way to handle the 3 second periods:

    1. In the TanThetaWentOutOfBounds handler (some other class that registers for the event) keep track of the time of the previous update and only take action when the event is raised within 3 second from the start of measuring. This way the responsibility of implementing the period is given to the consumer.

    2. You could decide to raise the event only if less then 3 seconds have passed since the previous time the event was raised. This way you restrict all the consumers to the period you are implementing in the raiser. Note that I used DateTime.Now to get the time, this is not as accurate as the Stopwatch class.

    Code:

    class A
    {
        private double _tantheta; // add public getter
        private DateTime _lastRaise = DateTime.MinValue;
        private bool _checkBoundaries; // add public getter/setter
        public event EventHandler TanThetaWentOutOfBounds;
        public void SetTantheta(double newValue)
        {
            if(_checkBoundaries &&
                (newValue < 0.6 || newValue > 1.5))
            {
                var t = TanThetaWentOutOfBounds;
                if(t != null)
                {
                    var now = DateTime.Now;
                    if((now - _lastRaise).TotalSeconds < 3)
                    {
                        t(this, EventArgs.Empty);
                        _lastRaise = now;
                    }
                }
            }
            else
            {
                _tantheta = newValue;  
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have event manager process that dispatches events to subscribers (e.g. http_session_created, http_sesssion_destroyed). If
I've run into an rather irritating problem in java. I have a program that
I'm new with boost. I have a program which uses dynamic_bitset inside a lambda
I have a question similar to the one here: Event handlers inside a Javascript
i have a click event for $('#blah div'). div has text inside of it
On Window 's load, every DD element inside Quote_App should have an onCLick event
I have some event handler on a boundary class that manages a persistence mechanism
I have an event handler that needs to determine a type and execute code
I have an event handler that will remove an element from a list of
I have a GUI problem that I would like to get sorted out, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.