I would recommend using an integer to represent the state and hide it with a boolean. Here is what I mean:
this.Working = true; try { // do something } finally { this.Working = false; }
Then we implement the Working property as follows:
private int working; public bool Working { get { return working > 0; } set { if (value) { working++; } else { working--; } } }
Internally, he simply remembers how many times it worked, as it was found, using this integer. If Working is 0 , you will return to normal.
You can install Working as many times as you want. As long as it is > 0 , it will return true . Remember to wrap your code in try...catch or you will lose count.
You can make an API call if Working set to false . Then set to true :
if (!this.Working) { // do API call this.TurnAppSettingsOff(); } this.Working = true; try { // do something } finally { this.Working = false; } if (!this.Working) { // do reset API call this.TurnAppSettingsOn(); }
source share