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

  • Home
  • SEARCH
  • 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 7948389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:42:31+00:00 2026-06-04T01:42:31+00:00

I ran into a variation of the problem I asked about here . Instead

  • 0

I ran into a variation of the problem I asked about here. Instead of a class extending System.Windows.Form, I have a class extending System.Windows.UserControl, which doesn’t have the FormClosing event.

I thought about adding a Close method to the user control, in which I tell the native thread to stop. When it stops, it raises an event to the user control, which calls Dispose on itself. The problem with this approach is that calling Dispose from the object to dispose (suicide?) seems a bad practice, and I had to write a finalizer that does nothing (to avoid double disposal), which feels even worse…

Suggestions?

Update: My user control lives inside a class which extends System.Windows.Forms.ToolStripControlHost, and an instance of that class lives in the main application form.

  • 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-04T01:42:33+00:00Added an answer on June 4, 2026 at 1:42 am

    I would add some sort of method to the user control and call it in the forms FormClosing event…

    The method in the user control would be blocking so that it didn’t return until the disposal was complete.

    But, you could cancel the closing in the Closing event, disable the form, do something in the background and when done, close the form from code. For example:

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        // if disposed, close as usual
        if (myControl == null || myControl.Disposed) return;
        // disable the form so nothing can be done while
        // were asynchronously disposing the form...
        this.Enabled = false;
        e.Cancel = true;
        var context = TaskScheduler.FromCurrentSynchronizationContext();
        Task.Factory.StartNew(()=>myControl.Dispose())
            .ContinueWith(a=>Close(), context);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Never ran into this problem with jQuery before. I have the following: $(document).ready(function() {
Ran into a problem. I have a spawned thread that must call its finally
I ran into this example for locking Windows workstation: using System.Runtime.InteropServices; ... [DllImport(user32.dll, SetLastError
I ran into the following problem and cannot decide how to proceed: I have
While extending a WIX-installer that I have to maintain, I ran into the following
Ran into an issue with a class; I have a class that looks like:
Ran into a very strange problem here using MVC3 and razor. The app I'm
I ran into an interesting dilemma today. I have a function that handles information
I ran into an interesting problem at work today. I got a request to
I ran into the situation where my class is making one asynchronous web call

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.