[Solved] Check every 2 seconds if a string value is changed [closed]

You might just be asking the wrong question only due to your lack of knowledge about features in the language.

Checking every 2 seconds, you could look into running a separate task that delays 2000 milliseconds and checks and does something.

You could have a backgroundworker thread doing similar.

You could create public getter/setter so that when it DOES change, you can act on it. This way you dont waste resources checking every two seconds. This last option MIGHT work for you.

public class YourExistingClassSomewhere
   private string _myString = "just setting to a default start value";
   public string MyString
      get {return _myString;}
      set {
            // even if attempting to assign a new value,
            // if the incoming new value is the same, just get out.
            if( _myString == value )

            // it was a different value, save it           
            _myString = value;
            // Then you could call some other method to display message.

   public void DoWhenStringChanges()
      Messagebox.Show( "it changed: " + MyString );

   public YourExistingClassSomewhere()
      MyString = _myString;  // try to set it to its own value, no change made

      MyString = "something new";  // this will trigger the message notification

You could ALSO do via exposing an “event” which exposes an event handler that other objects can get registered with, so when something happens, ANYTHING that is registered to the event gets notified. So, it does not have just one output reach. I could post that option as well if you think that might help.

solved Check every 2 seconds if a string value is changed [closed]