Is there a way in C# to check if an object is suspend? I have a TreeView that I need to know if it is still suspend.
myTreeView.BeginUpdate(); myTreeView.SuspendLayout(); // Do Stuff. myTreeView.EndUpdate(); myTreeView.ResumeLayout();
Because i have this code in a recursive function I want to know if the TreeView is already been suspended.
Following on from verminity’s answer you do have one option:
Use the following class
Then use this class for everything internally where you need to suspend it.
Obviously this won’t work if you ever pass the class around to something that only expects a control or if something else outside your control sets it.
If this is the case you would be forced to go with a variety of less than pleasant solutions:
For your needs if and only if you control the runtime versions this operates on entirely (i.e. a controlled corporate environment) the following evil but effective hack is appropriate. So long as you test any time you upgrade it may well keep working with little effort.
Attach this to your TreeView and then you can inspect the value whenever you like.
To reiterate this is fragile and entirely inappropriate for an environment where the version of the underlying runtime is not strictly controlled and where you can handle possible significant efforts to fix this on a breaking change. You would do well to include a static initializer which checks if the field actually existed and was the right type and aborted if not.