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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:56:41+00:00 2026-05-24T02:56:41+00:00

I’m using the ToolStripDropDown to show up an selectionpopup. The ToolStripDropDown contains a few

  • 0

I’m using the ToolStripDropDown to show up an selectionpopup.

The ToolStripDropDown contains a few custom controls with running Threads.
The Threads ends with the OnHandleDestroyed event, but for some reason the ToolStripDropDown doesn’t dispose/destroy it’s handle after closing.

Disposing the ToolStripDropDown on the closed-event gives me an exception because anything still accesses the ToolStripDropDown.

How do I know if the custom Control is still in use or not to end the thread?

Custom-Control:

public class CControl : Control
{
    Thread StyleThread;
    Object lockOBJ = new Object();
    bool abortthread = false;

    public CControl()
    {
        this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
        this.SetStyle(ControlStyles.Selectable, false);

        StyleThread = new Thread(new ThreadStart(this.StyleDelegate));
    }

    
    protected override void OnHandleCreated(EventArgs e)
    {
        base.OnHandleCreated(e);
        if(!StyleThread.IsAlive)
            StyleThread.Start();
    }

    protected override void OnHandleDestroyed(EventArgs e)
    {
        base.OnHandleDestroyed(e);
        lock (lockOBJ)
        {
            abortthread = true;
        }
        if (StyleThread.IsAlive)
        {
            StyleThread.Join(100);
        }
    }
    
    ...
}

ToolStripDropDown-Control:

public class AddPopUp : UserControl
{
    /*
        ------------------------------------
        This Control contains some CControls
        ------------------------------------
    */

    public void Show(Control control)
    {
        TSDD tsdd = new TSDD(this);
        Point screenpoint = control.PointToScreen(new Point(0, 0));
        tsdd.Show(control,new Point(0, -tsdd.Height ));
    }
    
    class TSDD : ToolStripDropDown
    {
        private Control Control { get; set; }

        public TSDD(Control control)
        {
            this.Control = control;
            this.DropShadowEnabled = false;
            ToolStripControlHost ch = new ToolStripControlHost(control);
            this.Items.Add(ch);
        }

        protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
        {
            base.SetBoundsCore(x, y, Control.Size.Width + 16, Control.Size.Height + 18, specified);
        }

        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                unchecked
                {
                    cp.Style |= (int)0x80000000;
                    cp.Style |= 0x40000;
                }
                return cp;
            }
        }

        
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == 0x84)
            {
                m.Result = (IntPtr)1;
                return;
            }
            base.WndProc(ref m);
        }
    }
}

EDIT:

After same more testing i wasn’t able to dispose the toolstripdropdown.
As a workaround i’m just destroying the handle on close of the toolstripdropdown.

        protected override void OnClosed(ToolStripDropDownClosedEventArgs e)
        {
            base.OnClosed(e);
            this.DestroyHandle();
        }
  • 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-05-24T02:56:42+00:00Added an answer on May 24, 2026 at 2:56 am

    ToolStrips have a very persistent bug (claimed to be fixed, but I still have problems) where they register an event handler to SystemEvents.UserPreferenceChanged to be able to repaint if the user changes global style settings in the OS.

    The only workaround I have found is to remove the attached toolstrips by enumerating the handlers in the SystemEvents.UserPreferenceChanged and removing them upon disposal of the control.

    ToolStrip memory leak

    http://connect.microsoft.com/VisualStudio/feedback/details/115600/toolstrip-leaks-after-calling-dispose#

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am currently running into a problem where an element is coming back from
We're building an app, our first using Rails 3, and we're having to build

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.