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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:59:13+00:00 2026-06-04T22:59:13+00:00

I have two controls on my form: a listbox with a list of workers

  • 0

I have two controls on my form: a listbox with a list of workers and a panel which acts as a container for showing the details (cards) about their work.
When a user clicks on the worker’s name, I display cards on the panel. A card is a usercontrol with some fairly simple UI (2 groupboxes, 3 textboxes and several labels) and simple logic (setting forecolor of labels).

The cards are created in runtime. Previous cards are removed from the panel and the new ones get added – the number of cards per worker is 1 to 4. It gets interesting here.
Everything works fine until approx. the fifth click on the workers. It seems that GC kicks in and it takes about two seconds (0.3s x number of previously removed cards) for the old cards (previously removed) to get disposed and new ones shown. If moving between workers works great before, it gets painfully slow at that point.
After some exploring I’ve located the problem to lay in Dispose method of my usedcontrol. Call base.Dispose() takes about 0.3s.

Here’s my code:

private void ShowCards(List<Work> workItems) {
  var y = 5;
  panelControl1.SuspendLayout();
  panelControl1.Controls.Clear();

  foreach (var work in workItems) {
    var card = new Components.WorkDisplayControl(work);
    card.Top = y;
    card.Left = 10;

    y += card.Height + 5;

    panelControl1.Controls.Add(card);
  }

  panelControl1.ResumeLayout(true);
  Application.DoEvents();
}

What I’ve tried so far:

  • hiding cards instead of disposing – it works faster when moving
    between workers, but the penalty is paid when closing the form
  • hiding the cards and have a separate thread which disposes them – no change
  • test with adding 10 cards and disposing them immediately – slow
  • test with adding 10 cards and disposing them immediately in the constructor – FAST!
  • replaced DevExpress controls with “normal” – no change
  • manually disposing old cards instead of removing them when changing worker – every move between workers gets slower: for (var ix = panelControl1.Controls.Count - 1; ix >= 0; --ix) {
    panelControl1.Controls[ix].Dispose();}
  • profiling it – that’s how I’ve found the problem in Dispose. I can trace it down to Control.DestroyHandle
  • calling Controls.Clear() in Dispose method of my control – super strange behaviour and exceptions
  • removed all of the controls from my usercontrol – a little bit faster, but still slow
  • hiding panelControl1 when removing and adding cards – no change
  • turned background GC off – no change
  • adding cards with AddRange

Since the same functionality works fast when called from the constructor, I belive the reason must be somewhere in the (control) handles.

I just can’t find the reason for this strange behaviour. I would appreciate any ideas….

UPDATE: While researching connection between GC and Control.Dispose I found this excellent answer

  • 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. Editorial Team
    Editorial Team
    2026-06-04T22:59:16+00:00Added an answer on June 4, 2026 at 10:59 pm

    After [unsuccessful support from DevExpress], I did some testing and playing with the code and finally found the solution.

    The trick is in clearing the controls on the UserControl before disposing.

    One can modify Dispose method on the UC (this solution worked in some cases, but not in all of them) or hide the UC instead of removing it form panel and cleraring its Controls

    Solution 1:

    protected override void Dispose(bool disposing) {
      if (disposing && (components != null)) {
        components.Dispose();
      }
    
      Controls.Clear(); // <--- Add this line
    
      base.Dispose(disposing); 
      }
    

    Solution 2:

    Add a new method to the UC:

    public void ClearControls() {
      Controls.Clear();
    }
    

    and in my original question replace this line

    panelControl1.Controls.Clear();
    

    with this:

    for (var ii = panelControl1.Controls.Count - 1; ii >= 0; --ii) { 
      var wdc = panelControl1.Controls[ii] as Components.WorkDisplayControl;
      wdc.Visible = false;
      wdc.ClearControls();
    }
    

    It works (at least) 20 times faster, which is good enough.

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

Sidebar

Related Questions

within a form I have two listbox controls these controls are used for mapping
I have two simple related controls on a form, a delete button and a
I have a simple html form with two controls: input-text and input-file I need
I have a simple form, with two DateTimePicker-controls: One for date, and one for
I have a form that contains two listview controls. When I click on each
I've got a Windows Forms application with two ListBox controls on the same form.
Sir, I have two window forms, each form has some controls. I want to
I've got a form where I have two radio buttons and two interchangeable controls
I have two different grid controls on the same form. They share the same
I have made a form which adds controls dynamically with user selecting the type

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.