c# Timer record watcher execute action

Skythrust

Member
Jul 9, 2019
133
7
Hi there,

For a project I am creating a watcher which checks if a value is 0 or 1 every 5 seconds.
If the value changes from 0 to 1 it needs to execute an action, but when it has changed to 1
the action needs to be execute one time, if the value changes back to 0 and back to 1 another time.

Options;
  • I can stop the the timer
  • I can set the timer in sleep for x minutes

But there should be another way to do this, it is important that it will work every time.
So when the value changes every time from 0 to 1 it needs to activate an action one time.

Any advise how I can make this?
 

JayC

Always Learning
Aug 8, 2013
5,493
1,398
What I would do is create a localized integer in memory that stores the last value.

Code:
if(lastValue != currentValue){
      if(currentValue == 1){
            //System "Rising Edge" meaning the value was 0, now its 1
      }else{
            //System "Falling Edge" meaning the value was 1, now its 0
      }
}

lastValue = currentValue;
 

Users who are viewing this thread

Top