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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:07:13+00:00 2026-05-30T13:07:13+00:00

i have a modeless form. When the user is done with it, and they

  • 0

i have a modeless form. When the user is done with it, and they Close it, the form (and its associated resources) are no longer needed.

Correct programming demands that i dispose of anything that implements IDisposable (i.e. i cannot wait for a garbage collection to run). This includes myself, a WinForms Form.

What is the best or valid time for a form to call Dispose on itself?

In “other” languages, you could destroy a form from within the form
itself by calling Release:

void CloseButton(EventArgs e)
{
   this.Release();
}

This method causes the form to be destroyed after every instance
method has returned (and the form has processed all pending messages).

In this “other” language, it would be horribly wrong to call:

void CloseButton(EventArgs e)
{
   this.Free();
}

Because i am then freeing the object that i am running an method on out from under myself;
which causes an access violation momentarily.

i assume it dangerously invalid to call:

void CloseButton(EventArgs e)
{
    this.Dispose();
}

But maybe it’s safe to call:

void FormClosed(EventArgs e)
{ 
   this.Dispose();
}

What’s the guidance on a modeless form cleaning up itself when it’s no longer needed?

  • 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-30T13:07:15+00:00Added an answer on May 30, 2026 at 1:07 pm

    Turns out you don’t even need to call Dispose on a modeless form. From MSDN:

    Form.Close Method

    When a form is closed, all resources created within the object are
    closed and the form is disposed. You can prevent the closing of a form
    at run time by handling the Closing event and setting the
    Cancel property of the CancelEventArgs passed as a parameter
    to your event handler. If the form you are closing is the startup form
    of your application, your application ends.

    The two conditions when a form is not disposed on Close is when:

    1. it is part of a multiple-document interface (MDI) application, and the form is not visible
    2. you have displayed the form using ShowDialog.

    In these cases, you will need to call Dispose manually to mark
    all of the form’s controls for garbage collection.

    So to answer my question, “What would be a good time for my modeless form to dispose of itself?”

    Answer: Never

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

Sidebar

Related Questions

I have a WPF application that hosts a modeless Win32 form. Everything runs smoothly,
I have a modeless dialog that overrides closeEvent() in order to save its state.
I like to write a modeless dialog based app, but I have a problem.
I have a very weird behaviour in a screen with a modeless dialog and
I need to display a modeless message box whenever a user hovers over a
I have a modeless dialog box being generated which prompts users to open a
I always have trouble remembering whether the modal or modeless dialog is the one
I have a link for menu profile. It has a class called 'user-button'. When
I have a modeless dialog which i need to show multiple instances of it
Have an XML with next form: <categories someAttribute=test> <category id=1> <title></title> </category> <category id=1>

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.