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 186103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:35:18+00:00 2026-05-11T15:35:18+00:00

Is there a way in C# to check if an object is suspend? I

  • 0

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.

  • 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. 2026-05-11T15:35:18+00:00Added an answer on May 11, 2026 at 3:35 pm

    Following on from verminity’s answer you do have one option:

    Use the following class

    public class SuspendAwareTreeView : TreeView     {     public readonly T RealControl;     private int suspendCount;      public bool IsSuspended      {          get { return suspendCount > 0; }     }      public Suspendable(T real) { this.RealControl = real; }      public void SuspendLayout()      {          this.suspendCount++;         this.RealControl.SuspendLayout();     }      public void ResumeLayout()      {          this.RealControl.ResumeLayout();         this.suspendCount--;     } } 

    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:

    • Write a new User control which wraps the TreeView and defers all calls to it but maintains the suspended state.
      • the resulting instance is no longer ‘is-a TreeView’ which will cause problems.
      • maintenance effort possibly high.
      • if for some reason the treeview ever decided to suspend itself this will break.
      • new version of the runtime unlikely to break anything, you simply won’t gain new functionality without effort.
    • Implement an entirely new TreeViewEx which exposes this state
      • the resulting instance is no longer ‘is-a TreeView’ which will cause problems.
      • maintenance effort possibly high
      • can never break since you have total control, can diverge from original though
      • new version of the runtime unlikely to break anything, you simply won’t gain new functionality without significant effort (possibly in violation of the law/EULA).
    • Violate Encapsulation
      • No alteration fo the type system, everything else continues to work.
      • Maintenance effort potentially high on runtime change
      • apps will break if the runtime changes underneath them

    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.

    public class ControlInvader {   private static readonly System.Reflection.FieldInfo layoutSuspendCount =        typeof(Control).GetField('layoutSuspendCount',           System.Reflection.BindingFlags.Instance |            System.Reflection.BindingFlags.NonPublic);    private readonly Control control;            public bool IsSuspended    {     get      {       return 0 != (byte)layoutSuspendCount.GetValue(this.control);     }   }    public Suspendable(Control control) { this.control = control; }      } 

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a simple way to check the type of an object? I need
I have an Object in java. Is there a way to check if an
Is there a way in java to check if a specific object is in
I was wondering if there is any way to check if an object is
Is there a better way to check if an object is empty? I'm using
Is there any way to check within JavaScript if XMLHttpRequest object supports W3C Progress
is there a way to check if an object can be fetched by the
Is there a way to check if a Thread object has had start called
Is there a way to check if a java Date object is Monday? I
Is there a nice way to check whether object o is a builtin Python

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.